Copy folders (not one file) using SSH ubuntu?

416,301

You can use secure copy (scp) with the recursive option (-r):

scp -r /path/to/local/dir user@remotehost:/path/to/remote/dir

Alternatively, I recommend rsync because you can resume transfers if the connection breaks, and it intelligently transfers only the differences between files:

rsync -avz -e 'ssh' /path/to/local/dir user@remotehost:/path/to/remote/dir

Note that in both cases you should be careful of trailing slashes: moving /path/to/local/dir to remotehost:/path/to/remote/dir/ results in /path/to/remote/dir/dir

Share:
416,301

Related videos on Youtube

aero
Author by

aero

Updated on September 18, 2022

Comments

  • aero
    aero over 1 year

    I am trying to copy a folder to remote Ubuntu server using command line ssh connection, i understand it's doable to transfer a file using scp but i have many files in a folder iam trying to copy to that remote server, how is that done? anyone? Thank you.

  • CKM
    CKM about 7 years
    Won't it ask for remote machine's password? I tried the above command and got Host key verification failed.
  • amc
    amc about 7 years
    Depends on the ssh server setup, but generally yes, it will use a key to authenticate and fallback to password if it's allowed.
  • WestCoastProjects
    WestCoastProjects about 4 years
    This is seriously slow. Any better /much faster alternatives?
  • WestCoastProjects
    WestCoastProjects about 4 years
    Much much faster approach is here unix.stackexchange.com/a/10037/66602
  • amc
    amc about 4 years
    Sure. If you compress things first then only rsync the tarball (and later decompress) then it could be faster. This doesn’t change the core answer.
  • Atul
    Atul about 4 years
    rsync command given here just kept waiting for me. For me, this worked like charm
  • Franva
    Franva almost 3 years
    I have my ssh private key, how can I use it with scp?