Take the 2-minute tour ×
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 linuxjournal.com/article/8904 It mounts the remote file system locally. –  Alan Dec 24 '13 at 9:57
2  
@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
add comment

4 Answers 4

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
1  
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
    
jmc, nope, I meant it like that. If you're shelled into System B via ssh, you can then execute scp on System B to copy files between System B and some other server ("System C"). The scp process will run on System B, which is the "local" system as far as it will be concerned. –  Garrett Albright Dec 25 '13 at 5:41
add comment

Install sshfs:

sudo apt-get install sshfs

create a empty dir

mkdir /home/user/testdir

"link" or "mount" the two directories

sshfs user@server.com:/remote/dir /home/user/test

"unlink" the dirs

fusermount -u /home/youruser/remotecomp

For more see here, linuxjournal.com

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
add comment

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
add comment

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

share|improve this answer
add comment

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