6.3.1 ProblemYou want to copy files securely from one computer to another. 6.3.2 SolutionFor one file: $ scp myfile remotehost: $ scp remotehost:myfile . For one file, renamed: $ scp myfile remotehost:myfilecopy $ scp remotehost:myfile myfilecopy For multiple files: $ scp myfile* remotehost: $ scp remotehost:myfile\* . To specify another directory: $ scp myfile* remotehost:/name/of/directory $ scp remotehost:/name/of/directory/myfile\* . To specify an alternate username for authentication: $ scp myfile smith@remotehost: $ scp smith@remotehost:myfile . To copy a directory recursively (-r): $ scp -r mydir remotehost: $ scp -r remotehost:mydir . To preserve file attributes (-p): $ scp -p myfile* remotehost: $ scp -p remotehost:myfile . 6.3.3 DiscussionThe scp command has syntax very similar to that of rcp or even cp: scp name-of-source name-of-destination A single file may be copied to a remote file or directory. In other words, if name-of-source is a file, name-of-destination may be a file (existing or not) or a directory (which must exist). Multiple files and directories, however, may be copied only into a directory. So, if name-of-source is two or more files, one or more directories, or a combination, then specify name-of-destination as an existing directory into which the copy will take place. Both name-of-source and name-of-destination may have the following form, in order:
Although each of the fields is optional, you cannot omit them all at the same time, yielding the empty string. Either the hostname (item 2) or the directory path (item 3) must be present. Whew! Once you get the hang of it, scp is pretty easy to use, and most scp commands you invoke will probably be pretty basic. If you prefer a more interactive interface, try sftp , which resembles ftp. If you want to "mirror" a set of files securely between machines, you could use scp -pr, but it has disadvantages:
A better alternative is rsync with ssh, which optimizes the transfer in various ways and needn't follow symbolic links: $ rsync -a -e ssh mydir remotehost:otherdir Add -v and progress for more verbose output: $ rsync -a -e ssh -v --progress mydir remotehost:otherdir 6.3.4 See Alsoscp(1), sftp(1), rcp(1), rsync(1). |