Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

This question already has an answer here:

I'm using Linux (centos) machine, I already connected to the other system using ssh. Now my question is how can I copy files from one system to another system?

Suppose, in my environment, I have two system like System A and System B. I'm using System A machine and some other using System B machine. I'm connected to System B machine. How can I copy a file from System B to System A?

share|improve this question

marked as duplicate by Gilles, slm, jasonwryan, Anthon, Bernhard Dec 25 '13 at 7:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I find scp to be a cumber stone often. If it could suite your needs, try this out It mounts the remote file system locally. – Alan Dec 24 '13 at 9:57
@Alan I think you mean "cumbersome"? Cumber Stone is a Magic card ;) – Izkata Dec 24 '13 at 14:47
somewhat related: make an encrypted archive of local dir/ on remote machine using ssh: tar -c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg' – J.F. Sebastian Dec 24 '13 at 20:49
If you has access of the ftp of the remote server, we can also use wget to download like $wget -r --level=9 --no-parent --reject "index.html*" ftp://<USERID>:<PASSWORD>@<MACHINE-NAME>/path/to Reference1 Reference2 – Mahendran Sakkarai Jan 19 at 6:22
If one of the answers here answered your question, please accept it. – DopeGhoti Nov 18 at 22:09

4 Answers 4

If you want to keep the files on both systems in sync then have a look at the rsync program:

(see tutorial here)

share|improve this answer

Sometimes you need to get fancy with tar:

tar -C / -cf - \
  opt/widget etc/widget etc/cron.d/widget etc/init.d/widget \
  --exclude=opt/widget/local.conf | 
  ssh otherhost tar -C / -xvf -
share|improve this answer
+1 for creativity! – Norman H Jun 9 at 14:02

Install sshfs:

sudo apt-get install sshfs

create a empty dir

mkdir /home/user/testdir

"link" or "mount" the two directories

sshfs /home/user/test

"unlink" the dirs

fusermount -u /home/youruser/remotecomp

For more see here,

share|improve this answer
The question specifically states that the OS in question is CentOS; not Debian-derived. apt-get is a Debianism; the correct package manager would be yum or, for really old flavors of CentOS, up2date or rpm. – DopeGhoti Dec 24 '13 at 21:30
+1 the answer for this question may be off context, but it still helped me, and as far as I can see, others too. – osirisgothra Jul 23 '14 at 15:27
Not related, but it's a one million dollar answer xD – Ramy Al Zuhouri May 15 at 16:55
+1 for an alternatively creative solution – Norman H Jun 9 at 14:03

To copy a file from B to A while logged into B:

scp /path/to/file username@a:/path/to/destination

To copy a file from B to A while logged into A:

scp username@b:/path/to/file /path/to/destination
share|improve this answer
To clarify, you typically don't use scp to copy a file to or from your local machine (System A) while logged in to a remote server (System B) with ssh. scp will log you into the remote server, copy the file, then log you out again in one process, so just run it from a shell on your local machine. That being said, you can use scp if you're logged into System B via SSH and want to copy files between System B and System C. – Garrett Albright Dec 24 '13 at 16:40
@GarrettAlbright, I think the one but last System B should be a System A, right? So: "That being said, you can use scp if you're logged into System A via SSH and want to copy files between System B and System C." – jmc Dec 24 '13 at 17:38
I didn't think you could scp from one remote location to another remote location. I recall trying it once and being admonished by scp. – DopeGhoti Dec 24 '13 at 20:01
Also, an important thing to remember is that you can only scp to a folder on the target machine to which you have permissions. If you are trying to copy it to a destination to which the target user does not have permission, first copy the file to the user's home directory or sub directory and then ssh into the target machine and sudo move it over to the final destination – shaveenk Apr 25 at 20:30
Remember -r (recursive) and -p (preserve system metadata): scp -rp <file1> <file2> – Rutrus Jul 1 at 7:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.