Use scp to securely transfer files

  • June 20, 2007
  • Avatar for peter

OpenSSH is a great tool for remotely logging in to other computers in a secure manner and then being able to use them from anywhere around the world. What the ssh command doesn't offer you normally however is a way to securely transfer files between your local machine and the remote machine.

That's where scp comes in. It stands for Secure Copy and piggybacks off the SSH infrastructure to send files to move files to and from the two machines. scp is a standard part of the OpenSSH suite, so it should be available almost everywhere.

It's also pretty simple to use. The basic syntax is as follows. To transfer a local file to a remote server, you will do something a bit like this:

$ scp ~/localfile user@remotehost:/remote/directory/file

This will copy the file localfile in your home folder to /remote/directory/file on the server. Once you hit enter, you'll be asked for your SSH password or passphrase as you would in a normal SSH session.

To reverse the process and copy a remote file to your system, simply reverse the two file operands.

$ scp user@remotehost:/remote/directory/file ~/localfile

That's basically it, it is a very simple tool to use. You will get a nice progress meter complete with download/upload speeds as the file gets transferred and once the deed is done, you'll be dropped back to your shell.

There are, of course, more advanced options if you have a complex setup (for example -p portnumber for alternative ports), which you can read up on by using the man page.

Avatar for peter Peter Upfold

Home » Articles »