For a few years now I keep catching myself transferring files between Linux servers, in a silly way…

What I mean is using somthing 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.

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.

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/

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/