«

»

May 10

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!!!

About the author

vHersey

Hersey Cartwright is an IT professional with extensive experience designing, implementing, managing, and supporting technologies that improve business processes. Hersey is Solutions Architect for SimpliVity covering Virginia, Washington DC, and Maryland. He holds the VMware Certified Design Expert (VCDX-DV #128) certification. Hersey actively participates in the VMware community and was awarded the VMware vExpert title in 2016, 2015, 2014, 2013, and 2012. He enjoys working with, teaching, and writing about virtualization and other data center technologies. Follow Hersey on Twitter @herseyc

11 comments

Skip to comment form

  1. Mike Brown

    Hey man,

    This was perfect. WinSCP wasn’t working too well for me. I was trying to copy page file vmdk templates between hosts across sites for an SRM implementation. WinSCP kept timing out, but this worked great. Thanks a lot.

    Mike

    http://VirtuallyMikeBrown.com
    https://twitter.com/VirtuallyMikeB
    http://LinkedIn.com/in/michaelbbrown

    1. vHersey

      Thanks for stopping by and glad you found this useful.

      1. 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.

        1. vHersey

          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

  2. labiol

    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.

    1. vHersey

      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

  3. SysAdmin-E

    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.

  4. Tacl

    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

    1. David

      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.

      1. 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.

  5. 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?

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

14 − 9 =