vHerseyVMware

Copy files between ESXi hosts using scp

I have been asked how to do this twice in so many days. So here is a quick post on how to copy files between the local datastores on standalone ESXi hosts without access to shared storage. There are a number of ways to accomplish this, one way is using scp at the ESXi command line.

SSH access has to be enabled on the host you are copying to (and on the host you are copying from if you are accessing it via SSH).

scp path_to_file_to_copy root@FQDN_or_remote_host_ip:path_to_new_file_location

scp-capture

For example if you have an ISO named Win.iso on the local datastore1 of ESXi-1 (192.168.1.25) and you want to copy it to the local datastore1 of ESXi-2 (192.168.1.201):

scp /vmfs/volumes/datastore1/Win.iso root@192.168.1.201:/vmfs/volumes/datastore1/Win.iso

You will be prompted for the root password of the remote host and once you have successfully authenticated the file will copy.

I know this works on ESXi 5.x hosts, not sure about earlier versions. Again make sure SSH is enabled on the remote host.

Happy Friday!!!

11 thoughts on “Copy files between ESXi hosts using scp

    • Thanks for stopping by and glad you found this useful.

      Reply
      • Denise Banh

        This is a great post. Thank you.

        Can you use the same comand ‘scp’ to copy a folder that holds the template from one datastore to another datastore? Same host but one datastore is local and the other datastore is remote.

        Thank you and I look forward to your reply.

        Reply
        • Denise,

          To copy files or folders between datastores on the same host you can just use the copy command – cp

          cp -r

          For example cp -r /vmfs/volumes/datastorename/sourcefolder /vmfs/volumes/datastorename/targetfolder

          Hersey

          Reply
  • On ESXi 5.0 and above you can experience timeout while connecting between ESXi host. This is because of ESXi firewall setting. If you want to send file or get ssh connection between ESXi host you will have to change sshClient firewall settings. Needed cli commands you can find here: http://labiol.net/?e=108.

    Reply
    • labiol,

      Thanks for stopping by and thanks for the input. Yes the outbound firewall rule for the SSH Client must be open and also the inbound rule for the SSH Server. This can be done using the esxcli as you have demonstrated in your blog post and also from the vSphere Client in Host -> Configuration -> Security Profile. Generally the inbound rule for the SSH Server is enabled when you enable the SSH Server on the host (also done through the Security Profile settings).

      Thanks again and appreciate the input.

      Hersey

      Reply
  • As labiol mentioned, the outbound firewall rule for SSH Client must be enabled. This should be clearly stated in the instructions. I spent 15 minutes trying to figure out what I was doing wrong until I decided to check the comments to see if anyone else had trouble getting this to work.

    Reply
  • Hi Hersey,

    I am trying to move vm from one ESXi to another ESXi server. Do you think its necessary to move the entire vm folder or just the .vmdk and .vmx files will do ?

    Thanks in advance.
    tacl

    Reply
    • Tacl,

      I would be interested in this reply. I had been previously shutting down my Windows Domain Server to export as an ova for backup purposes. (That’s scary, because if something happened, I’m not sure if I’d be able to log back in to power on my domain controller.)

      Then, I came across a site which mentioned copying the vmdk and vmf files is sufficient to clone a vm. I’m not entirely sure what all of the other files in the directory are for.

      Reply
      • Cameron

        I would be careful doing this. I would do a system state backup to avoid running into a USN role back if you ever have to restore to a backup.

        Reply
  • Husain

    When copying vmdk files using either cp or scp I’ve noticed that the virtual disk type changes from Thin provisioned to Thick provisioned. Is there a way to maintain the virtual disk type?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

seventeen − thirteen =