Upload files with ssh / scp in Linux

The following code will transfer myfile.zip to the folder ‘myfolder’ on the server:

Code:
scp /home/username/documents/myfile.zip username@myserver.com:/home/username/myfolder/

scp = Linux command to transfer files ‘Secure Copy’
/home/username/documents/ = the directory where myfile.zip resides
myfile.zip = the file to transfer
username@myserer.com = username on myserver.com
/home/username/myfolder/ = the directory on myserver.com where myfile.zip should be transferred

You can also do the same in reverse:

Code:
scp username@myserver.com:/home/username/myfolder/myfile.zip /home/username/documents/

If you want to transfer a directory, just leave the trailing ‘/’ and add the ‘-r’ flag:

Code:
scp -r username@myserver.com:/home/username/myfolder/ /home/username/documents/

If you are connecting to Amazon hosting or need to use an identity file, try the following:

Code:
scp -v -r  -i ~/.ssh/identity.pem ~/Documents/myfolder/ username@myserver.com:/home/username/

-v Verbose – see the file transfer progress
-r Recursive – transfer a directory and all files inside
-i ~/.ssh/identity.pem Identity – use the identity file located at ~/.ssh/identity.pem
username@myserer.com = username on myserver.com
/home/username/ = the directory on myserver.com where myfolder should be transferred

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please enter 10 numbers for Captcha: * Time limit is exhausted. Please reload the CAPTCHA.