How to copy files from a virtual machine to a local machine?

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.')
5

2 Answers

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.

2

Here's how, provided you have FileZilla:

  1. in the Quickconnect box, enter sftp://yourserver, your username and password.SFTP 1
  2. Hit connectSFTP 2You 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 cacheSFTP 3
  3. Download those files!enter image description here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like