Chapter 19.) The idea behind scp is that it works just like cp (the standard copy command) — except that it also works on remote files that you own or that you at least have access to. To refer to a file on another machine, type the machine name and a colon before the filename. To copy a file named mydata from the machine named pumpkin and call it pumpkindata , you type
scp pumpkin:mydata pumpkindata
To copy it the other way (from a file called pumpkindata on your machine to a file called mydata on a machine called pumpkin ), you type this line: scp pumpkindata pumpkin:mydata
The scp program uses the same username rules as does ssh . If your username on the other system is different from that on your own system, type the username and an @ sign before the machine name: scp steph@pumpkin:mydata pumpkindata
If you want to copy files in another user’s directory (tracy , for example) on the other system, place the user’s name after a ~ (a tilde) before the filename. Suppose that you need one of Tracy’s files: scp pumpkin:~tracy/somefile tracyfile
To copy an entire directory at a time, you can use the -r (for recursive) flag to tell scp to copy the entire contents of a directory: scp -r pumpkin:projectdir .
This command says to copy the directory projectdir on machine pumpkin into the current directory (the period is the nickname for the current directory) on the local machine.You can combine all this notation in an illegible festival of punctuation: scp -r steph@pumpkin:~tracy/projectdir tracy-project
Translation: “Go to machine pumpkin , where my username is steph , and get from user tracy a directory called projectdir and copy it to a directory on this machine called tracy-project ." Whew!Tip If you’re copying large files, scp gives you reassuring progress reports to tell you how it’s doing and when it thinks it’ll be done.sscp is done when you see the UNIX prompt.If you copy stuff to another machine and want to see whether it worked, use ssh to give an ls command afterward to see which files are on the other machine: scp -r projectdir pumpkin:squashproject ssh pumpkin ls -l squashproject
Although scp is reliable (if it didn’t complain, the copy almost certainly worked), it never hurts to be sure.