Remote File Copy from the Linux Command Prompt
Contents
SCP - Secure Copy Protocol
This utility is handy for transferring files from one Linux system directly to another using ssh security with authentication. Unline rcp, scp will ask for passwords or passphrases if they are needed for authentication.
Upload/PUSH (syntax):
scp </local/file(s)/to/transfer> <login-name>@<hostname>:</remote/dir/to/transfer/to>
Upload/PUSH (example):
scp index.html username@www.companyname.com:/usr/httpd/virtual/www.companyname.com/html
Download/PULL (syntax):
scp <your-login>@<hostname>:</path/to/remote/file> </local/directory>
Download/PULL (example):
scp -r username@www.companyname.com:/usr/httpd/virtual/www.companyname.com/html /mylocalpc/mywebsitedirectory
Useful options:
-p preserve timestamp and info -B batch mode -r recursive copy -C compression -v verbose mode -P port
Useful example: If you are using a remote server that you need to push files and directories to, and the remote server utilizes a nonstandard port, it might look like this (example):
scp -P 2800 -r ./* nicolep@customerwebhosting.robotz.com:/home/nicolep/awesomesite.com
Insecure File Copy
ie: Netcat File Copy. It's not really called Insecure File Copy, but to make a point, only use this method on your private LAN for files where security does not matter. This is the quick and dirty way to move a file even if ssh is not installed. Although netcat has many functions, you can copy a file from one machine to another using Netcat.
You basically issue the netcat command on the receive computer assigning a port with a redirect to file output. It will sit and listen for a connection then terminate when complete. Type this on the receive computer:
nc -l 2222 > myfile.pdf
Then on the source machine which is at IP address 192.168.50.1 in our example where the file exists you type the following:
nc 192.168.50.1 2222 < myfile.pdf
You don't have to use port 2222, and you call the file whatever you want as long as the extensions are the same, and so on.
For multiple files you can use tar to put them all in a tarball then expand on the destination
tar zc *.* | nc -l 2222
nc 192.168.50.1 2222 | tar zx
Remember that netcat simply reads data from stdin.
RZSZ - XMODEM, YMODEM, ZMODEM file transfer
This utility is handy for transferring files from a Microsoft Windows system to or from a Linux system over tcp/ip. It is also useful to transfer files to or from Linux systems using a serial cable and minicom. The RZSZ package includes (sx, sb, sz, rx, rb, rz) commands.
Upload (syntax):
Upload (example):
Download (syntax):
Download (example):
ZSSH - File transfer using Secure Shell and RZSZ
zssh (Zmodem SSH) is a program for interactively transferring files to and from a remote machine while using ssh. It is intended to be a convenient alternative to scp, allowing the transfer of files without having to open another session and re-authenticate. zssh is an interactive wrapper for ssh used to switch the ssh connection between the remote shell and file transfers. Files are transferred through zmodem protocol, using the rz and sz commands.
Upload (syntax):
Upload (example):
Download (syntax):
Download (example):
RCP - remote file copy
This utility is handy for transferring files from one Linux system directly to another using remote shell. It does not prompt for passwords, and it performs remote execution through rsh requiring the same authentication.
Upload (syntax):
Upload (example):
Download (syntax):
Download (example):