The traditional way to copy files from one computer to another is to use uucp, the UNIX-to-UNIX copy program, or to use one of the rtools, rcp. The rtools are insecure over a public network and are subject to several exploits. It is best not to use them at all because they have been supplanted by more secure tools based on the secure shell, ssh.
The file transfer protocol known as FTP can be used to copy files from one computer to another, but this requires that an FTP server be running, and the server is subject to security problems of its own.
See Chapter 23, "Remote File Serving with FTP," for more details on FTP.
The scp command uses ssh for file copying. Useful arguments for this command include -p Preserves modification times, access times, and modes from the original file. -r Recursively copies entire directories. -v Verbose mode for debugging problems. -c Enables file compression.
The syntax of an scp copy command is scp [arguments] [source] [target]
For example, if we want to copy the file /home/paul/ubuntu.txt to ~/docs on our account on a remote host
$ scp -p /home/paul/Ubuntu.txt [email protected]:/home/paul/docs
After it prompts us for a password, we see
This indicates that the transfer was completed. If we had subdirectories to transfer, we would have used the -r (recursive) argument.
Actually, it can be much easier than the example because scp assumes that all paths are relative to the home directory of the user unless the full path is given.
Taking this into consideration, our example becomes
$ scp -p Ubuntu.txt [email protected]:docs
And it can be made even easier. Creating a file named ~/.ssh/config with the following contents:
Host = titan
HostName = 192.168.168.5 User = paul ForwardAgent = yes ForwardX11 = yes Compression = yes allows us to simply use
$ scp -p Ubuntu.txt titan:docs
If you are comfortable with FTP, you might want to consider a cousin of scp: sftp. It provides the common FTP command set. If no sftp server is running on the remote host, simply use scp to copy the sftpserv binary to your remote home directory. (Often, ~/bin is in your path.) The FTP client gftp supports sftp and gives you a GUI client as well.
You can find more information on both scp and sftp in Chapter 19, "Remote Access with
SSH and Telnet."
Was this article helpful?