Secure Shell is a protocol that allows a secure connection to the remote computer. There are multiple methods to transfer files remotely via
SSH. The most common method is via
scp utility which comes with the
SSH implementation. Other methods, such as
rsync, are file transfer applications which secure there connection using
By using one of the previously mentioned methods, you can securely transfer a file from your local machine to a remote server and vise versa.
We will discuss each method in the section below
Keep in mind that you need to make sure that you have access right and correct permission to the remote server’s files and folders in order for these methods to work.
By the way, if you like to master command-line, Codecademy offers one of the best courses to learn command-line.
Transfer files using SCP
secure copy is considered to be the easiest among other methods. To work with this command, you need to specify the remote host’s
DNS name or
IP Address with the remote username. After hitting Enter, you will be prompted to enter the password for the remote user or you can setup key-based authentication, to avoid entering the password every time you copy a file. See the examples below:
1. Coping single file from local to remote.
In the above example, f the target folder (
/folder/) is not specified, it will copy the file to the remote user’s home directory.
2. Coping single file from remote to local.
3. Coping single file from remote to local current working directory with the same filename(
remotefile.txt) by using
. as the copy target.
4. Coping multiple files from local to remote.
5. Coping all files from local to remote.
6. Coping all files and folders recursively from local to remote.
Transfer files using SFTP
Secure FTP is just like
ftp but with secure connection. So, most of the commands are similar and can used the same way as with ftp. As you can see in the example below:
Transfer file using rsync
In this method, you are going to secure your
rsync session with
ssh. This is achieved by using
-e "ssh" with your normal
rsync command. In case you didn’t specify these options,
rsync will first try to connect to
rsyncd but it will automatically fallback to
rsyncd is not running on the remote system.
The above 2 commands will give the same result.
At the end of this article, I would like to mention that there are GUI applications that can also be used to transfer files remotely, such as WinSCP that support
scp method and
sftp too. The other tool is FileZilla, which is a very popular
FTP solution that also supports
sftp. And there are many others.
Other articles you may find interesting