You can copy files from the local system to a remote system or vice versa, or even between two remote systems using the "scp" command. To specify a file on a remote system, simply prefix it with the name of the remote host followed by a colon.
If you leave off the filename of the copy or specify a directory, only the name of the source file will be used. An easy way of retrieving a copy of a remote file into the current directory while keeping the name of the source file is to use a single dot as the destination. The following copies the file "mydata" from the remote system, chinookfe, to our local workstation WOMBATNET:
[WOMBATNET:/home/wombat]
$ scp -p chinookfe.ucar.edu:mydata .
mydata 100% |********************************| 6400 KB 00:06
[WOMBATNET:/home/wombat]
$
The "-p" option is not required. It indicates that the modification and access times as well as modes of the source file should be preserved on the copy. This is usually desirable.
You can use the "@" director, like we did in our login example, to copy files to/from a different account name on the remote system. In this example, we copy the file "mydata" from the account "foo" on chinookfe to our local workstation:
[WOMBATNET:/home/wombat]
$ scp -p foo@chinookfe.ucar.edu:mydata .
mydata 100% |********************************| 6400 KB 00:06
[WOMBATNET:/home/wombat]
$
Relative filenames resolve differently on the local system than on the remote system. On the local system, the current directory is assumed (as usual with all commands). On the remote system, the command runs in the home directory. Thus relative filenames will be relative to the home directory of the remote account.
In addition we can use the "-r" directive, for recursion, allowing us to copy entire directories:
[WOMBATNET:/home/wombat]
$ ls -al
drwxr-xr-x 8 wombat wombat 1024 Aug 12 09:24 .
drwxr-sr-x 12 wombat wombat 512 Jul 17 10:18 ..
drwxr-xr-x 2 wombat wombat 512 Aug 12 09:24 A001
[WOMBATNET:/home/wombat]
$ scp -r -p A001 chinookfe.ucar.edu:
mydata_00004 100% |*********************| 12800 KB 00:04
mydata_00001 100% |*********************| 12800 KB 00:04
mydata_00002 100% |*********************| 12800 KB 00:04
mydata_00003 100% |*********************| 12800 KB 00:04
We can also use "sftp" to transfer files in an interactive fashion, much like a standard ftp client:
[WOMBATNET:/home/wombat]
$ sftp chinookfe.ucar.edu:
sftp> pwd
Remote working directory: /home/chinook/wombat
sftp> get mydata
Fetching /home/chinook/wombat/mydata to mydata
sftp> exit
[WOMBATNET:/home/wombat]
$
If you have questions about this document, please contact SCD Customer Support. You can also reach us by telephone 24 hours a day, seven days a week at 303-497-1278. Additional contact methods: consult1@ucar.edu and during business hours in NCAR Mesa Lab Suite 39.