Hey Guys, In this tutorial, we will learn how to upload files via ssh using terminal.
Uploading files via ssh required when you don’t have any cPanel to work with like aws hosting which only provides you the SSH.
So we will be using the SCP (Secure Copy Protocal) for file transfer. Let’s start.
What is Secure Copy Protocal (SCP)
Secure copy protocol (SCP) is a means of securely transferring computer files between a local host and a remote host or between two remote hosts.It is based on the Secure Shell (SSH) protocol.
“SCP” commonly refers to both the Secure Copy Protocol and the program itself. According to OpenSSH developers in April 2019 the scp protocol is outdated, inflexible and not readily fixed; they recommend the use of more modern protocols like sftp and rsync for file transfer.
The SCP program is a software tool implementing the SCP protocol as a service daemon or client. It is a program to perform secure copying.
Typically, a syntax of scp program is like the syntax of cp (copy):
Copying file to host:
scp SourceFile user@host:directory/TargetFile
Copying folder from host:
scp user@host:directory/SourceFile TargetFile
scp -r user@host:directory/SourceFolder TargetFolder
Note that if the remote host uses a port other than the default of 22, it can be specified in the command. For example, copying a file from host:
scp -P 2222 user@host:directory/SourceFile TargetFile
If you’re working with aws hosting then you must have to use the key
scp -i yourkey.pem user@host:directory/SourceFile TargetFile
Let’s take an example:
scp -i mykey.pem /var/www/html/myfile.sql email@example.com:/var/www/htmlmyfile.sql