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))
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'))
    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')
print('Creating file...')
    import os
    del os
f = open('recv/' + filename.decode("UTF-8"), 'w')

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)
if answer == bytes("Passwords are not the same.", 'UTF-8'):
filename = input('File to send: ')
f = open(filename)
sock.sendall(bytes(filename, 'UTF-8'))
for x in f.readlines():
    sock.sendall(bytes(x, 'UTF-8'))
sock.sendall(bytes('', 'UTF-8'))
print('Connection closed.')
  • Have you tried setting up an SSH-server on the virtual machine and then using SFTP (with a client like FileZilla) to connect to the virtual machine from the host machine? – Pylsa Aug 2 '15 at 17:23
  • @up I did not but I would like to not install new packages (trying to keep ubuntu as smaller as possible) – vakus Aug 2 '15 at 17:26
  • Isn't SSH installed by default? If it is, it shouldn't be necessary to install additional packages. – Pylsa Aug 2 '15 at 17:27
  • It is installed but I have no idea how to setup ssh server and I cannot found anything that would help me with it – vakus Aug 2 '15 at 17:42
  • Added an answer with how to set up your SSH server. – Pylsa Aug 2 '15 at 17:57

If you want to use an SSH-server, try the following to set it up. I'm assuming your virtual machine doesn't need much security, as these instructions will open up root SSH logins for your guest machine. You could revert these changes when you're done.

I'm assuming the openssh server has already been installed.

  • Open up your openssh configuration file with your favourite text editor. If you're using vim for example:

    sudo vim /etc/ssh/sshd_config
  • Add to the bottom or make sure the lines below aren't commented out. If you don't use root but another user, ignore the first two lines:

    PermitRootLogin without-password
    PermitRootLogin yes
    PasswordAuthentication yes
  • Save the new configuration file.

  • Restart the SSH server:

    sudo restart ssh

Then simply connect to your guest machine using an SFTP client like FileZilla. Just enter the IP address, the details of your root (or other) user into the GUI and connect.

| improve this answer | |
  • Thanks for the information about setting up ssh server, but I still have one more question. When I try to connect with FilleZilla its says fzSftp started, protocol_version=2 and connection closed after 20 seconds of inactivity(or something like that I'm using Polish version) and try to connect again. Also Im not sure does IP is right. I used one from arp -an – vakus Aug 2 '15 at 20:57
  • Get the IP by executing ifconfig from the command line on your virtual Ubuntu machine. – Pylsa Aug 3 '15 at 0:35

Here's how, provided you have FileZilla:

  1. in the Quickconnect box, enter sftp://yourserver, your username and password. SFTP 1
  2. Hit connect SFTP 2 You will get a SSH warning stating that you don't have that host key cached. Optionally click Always trust this host, add this key to the cache SFTP 3
  3. Download those files! enter image description here
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.