How to copy directories via ssh

92,813

Solution 1

If you want to copy a directory from machine a to b while logged into a:

scp -r /path/to/directory user@ipaddress:/path/to/destination

If you want to copy a directory from machine a to b while logged into b:

scp -r user@ipaddress:/path/to/directory /path/to/destination

I don't quite understand what you mean by "doesn't clicked to me", I have used this method countless times before.

Solution 2

You can use cpio or tar to create an archive as a stream on standard output, pipe that to ssh and extract the stream on the remote host. For example, using tar:

tar cf - dir | ssh remotehost tar xf -

To extract the archive in a different directory on the remote host, use

tar cf - dir | ssh remotehost tar xfC - /path/on/remote

Solution 3

Think this might work for you:

scp file user@host:/location_to_save_file

scp - secure copy - the file(s) you want to scp to remote node - the user who has permissions to scp file, i.e sysadmin, etc @ - user and host separator host - the node you are scp the file(s) :/location_to_save_file - absolute path to save the file

Share:
92,813

Related videos on Youtube

hrk
Author by

hrk

Updated on September 18, 2022

Comments

  • hrk
    hrk almost 2 years

    I am connected with ssh and I want to copy a directory from my local to our remote server; how can I do that? I have read several post using scp but that doesn't worked for me. Some posts suggested using rsync but in my case I just wants to copy one directory.

  • Jean Frederic
    Jean Frederic about 4 years
    I think more intuitive answer would be "from machine b to a while logged into a" anybody can swap a in the head, but would indicate source/destination much better, unless I'm crazy :)
  • Erik
    Erik about 4 years
    @PawelCioch While I definitely agree with you, it's not difficult to comprehend. I did write this answer almost 3 years ago, and I wasn't very good with English :)