Situation: I have 2 computers: Pc_A and Pc_B. I am also using a SSH connection that goes from A to B.

My problem: I have a folder saved on the desktop of Pc_A and I need to copy it to the desktop of Pc_B via terminal. The thing is that once I open the terminal on Pc_A and I connect to Pc_B I'm no longer capable of transferring data from one computer to another...

Question: does anyone have the idea of what should be done in such case?

  • What do you mean exactly? You open a SSH connection from PCA to PCB, and when you do that, you're not able to copy anymore? Dec 12, 2014 at 23:55
  • 1
    when I open the terminal and i connect through ssh i can only see what i have on PCB; therefore if i wished to copy a folder from A to B i can't because i'm not able to select my files through the same terminal; the only way i can select my files is by opening a new terminal so i don't understand how i can copy a file form the terminal that is seeing PCA to the terminal connected with PCB Dec 12, 2014 at 23:58
  • I see. Use one of the answers we posted here (also, as I see that you're new here, press the checkmark on one of them if that answer works out for you). Dec 12, 2014 at 23:59

2 Answers 2


You could use scp:

When you're on PCB:

scp -r your_user_name@ip_address_of_PCA:/path/to/remote/directory /path/to/local/directory
  • 4
    It worked but I had to slightly modify it: scp -r /path/to/local/directoryyour_user_name@ip_address_of_PCB:/path/to/remote/directory Dec 13, 2014 at 0:26
  • 1
    You're right, I mistook PCA for PCB in my command. It's nice that you found out yourself. You see how flexible it is. Dec 13, 2014 at 0:43
  • 2
    scp -i <your ssh key file> -r ...
    – truongnm
    Aug 28, 2018 at 4:21

On PC A, instead of connecting to PC B by ssh, just run

rsync /path/to/local/file username@PCB:/path/to/remote/destination

You could also use scp instead of rsync, with similar formatting for the rest of the line, but I prefer rsync, since it's more powerful, and (I think) verifies after copying. See man rsync for more details. N.B. that the remote computer must have rsync installed too (see comments by neon_overload), otherwise scp would be preferred.

If installed on both computers, rsync will take advantage of the processing power of both. For example, it can compress files before transfer, by using the -z flag.

  • More info: This works because rsync can transfer over SSH to other computers that have rsync installed: PCB: signifies a remote connection over SSH. Dec 13, 2014 at 1:30
  • @neon_overload I thought that having rsync installed on the remote computer was not necessary, but if it were, then this could potentially speed up transfers. I can't seem to find a reference though.
    – Sparhawk
    Dec 13, 2014 at 1:33
  • It's pretty standard for rsync to be on any given system, and available with just the command "rsync", so it usually "just works". It connects via SSH, starts rsync on the remote system with the "rsync" command, and then the rsync processes at each end communicate with each other over the already open SSH connection. All this works so transparently to the user that it's deceptively simple, but you benefit from an rsync process at each end to compare file sizes, modification times and do checksums to save data transfer. Dec 13, 2014 at 10:55
  • FWIW this says that "rsync" must be in the logged in user's execution path on the remote computer. troy.jdmz.net/rsync Dec 13, 2014 at 10:56
  • 2
    Fair question, so I just tried removing rsync on a remote machine and trying to rsync to it. I get: bash: rsync: command not found rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: remote command not found (code 127) at io.c(605) [sender=3.0.9]. Replacing rsync on the remote machine fixed it. Dec 13, 2014 at 11:14

Not the answer you're looking for? Browse other questions tagged .