I have a virtual machine on Virtualbox with Ubuntu 15.04 (Command Line Interface only) and I want to copy files from the virtual machine to the host. As I have only CLI, I cannot use shared folders.
I have tried to access my USB drive from Virtualbox but it didn't help (I had to format hard drive after connecting to windows).
Is there any way to copy files from Ubuntu 15.04 (Virtual machine) to Windows 7 or USB drive?
My answer: I marked one answer as good, but I managed to solve my problem before it. I created two python programs. one send file, second receiving file.
If someone need this program here is code: (in both change xxx.xxx.xxx.xxx for IP of fileServer)
fileServer.py (on computer that you want to recieve files):
import socket print('File server V 1.0 by vakus') serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) serv.bind(('xxx.xxx.xxx.xxx', 9999)) serv.listen(1) conn, addr = serv.accept() print('Incoming Connection. Please write password:') pas = bytes(input(), 'UTF-8') conpass = conn.recv(1024) if conpass != pas: print('Passwords are not the same. closing connection') conn.sendall(bytes('Passwords are not the same.', 'UTF-8')) conn.close() exit() else: print('Passwords are the same.') conn.sendall(bytes('Passwords are the same.', 'UTF-8')) filename = conn.recv(1024) file = "" while True: data = conn.recv(1024) if not data: break file += data.decode('UTF-8') print(data.decode('UTF-8'), end='') print('Close connection') conn.close() print('Creating file...') try: import os os.mkdir('recv') del os except: pass f = open('recv/' + filename.decode("UTF-8"), 'w') f.write(file) f.close()
fileTransmiter.py (on computer that send file):
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('xxx.xxx.xxx.xxx', 9999)) sock.sendall(bytes(input('Password: '), 'UTF-8')) answer = sock.recv(1024) print(answer) if answer == bytes("Passwords are not the same.", 'UTF-8'): exit() filename = input('File to send: ') f = open(filename) sock.sendall(bytes(filename, 'UTF-8')) for x in f.readlines(): print(x) sock.sendall(bytes(x, 'UTF-8')) sock.sendall(bytes('', 'UTF-8')) sock.close() print('Connection closed.')