scp examples

scp is used to transfer files from one machine to another. scp stands for Secure CoPy, and provides the same security as ssh (i.e., all traffic between hosts is encrypted).

To transfer a file called myprog.py from the computer you are on (maybe your laptop?) to another computer called oil.cs.swarthmore.edu:

scp myprog.py oil.cs.swarthmore.edu:.

Note the trailing dot (.) at the end of that command. That says "name the copied file the same name (myprog.py) on the other computer.

Note also, the above will try to log you in on oil.cs.swarthmore.edu as the same user on the current computer.

So if you have username harry on the current computer, and username hpotter1 on the CS computers, you'll need to log in as user@host like this:

scp myprog.py hpotter1@oil.cs.swarthmore.edu:.

To copy an entire directory (myprogs), use the -r (recursive) flag:

scp -r myprogs hpotter1@oil.cs.swarthmore.edu:.

Finally, to go the other way and copy files from a remote machine back to your current machine, just swap the source and destination:

scp hpotter1@oil.cs.swarthmore.edu:cs21/myprog.py .

The above tries to copy a file called myprog.py from the cs21 directory on oil.cs.swarthmore.edu. Again, note the trailing dot (.) on that command line.


Back to SwatCS Help Docs