For a few years now I keep catching myself transferring files between Linux servers in a silly way…
What I mean is using something like FTP, or copying to my desktop and then up to the other server – all hassle (and in the case of FTP – inherently insecure). Why do I do this? Well not because there’s no alternative, but because I can never easily remember how to do it the “proper” way.
The Proper Way: SCP
So how to do it – simply use SCP. This copies a file using SSH and so is more secure (we trust SSH right?), even better I’ve never had a server which doesn’t support it out of the box.
Basic File Transfer
Right so how to transfer one file:
scp /sourcedir/filename.extension user@serverip:/destinationdir/
It’s quite simple really – if you run SSH on an abnormal port (you really should it cuts down the attacks) then you can specify the port like this:
scp -P 2100 /sourcedir/filename.extension user@serverip:/destinationdir/
Transferring Multiple Files
Also, if you want to transfer multiple files (e.g. all the images in a directory) then you can just use wildcards – like below:
scp -P 2100 /sourcedir/*.extension user@serverip:/destinationdir/
Additional Useful Options
Here are some other helpful SCP options that can make file transfers even more efficient:
- -r: Recursively copy entire directories
scp -r /sourcedir/ user@serverip:/destinationdir/
- -C: Enable compression during the transfer
scp -C /sourcedir/largefiles.tar user@serverip:/destinationdir/
- -v: Verbose mode to see detailed transfer information
scp -v /sourcedir/filename.extension user@serverip:/destinationdir/
- -q: Quiet mode to suppress progress meter and warning messages
Why SCP is Better
Using SCP provides several advantages over FTP or manual transfers:
- Security: All transfers are encrypted through SSH
- Simplicity: No need to install additional software
- Efficiency: Direct server-to-server transfers save bandwidth and time
- Authentication: Uses your existing SSH keys/credentials
So next time you need to move files between Linux servers, skip the FTP client and use SCP directly. Your data will be more secure, and you’ll save valuable time.