How to copy the files to the remote server using SSH

There are 3 Methords to transfer files remotely

Transfer file using scp
Transfer file using sftp
Transfer file using rsync

Method 1. SCP file transfer Method.

Basic syntax for SCP


In case if you want to copy complete directory use -r command for <OPTIONS>


Example :

Copy single file from local to remote.

scp file.txt [email protected]_or_ip:/remote/folder/

Copy multiple files from local to remote.

scp file.txt file.txt [email protected]_or_ip:/remote/folder/

Copy all files from local to remote.

scp * [email protected]_or_ip:/remote/folder/

Copy all files and folders recursively from local to remote.

scp -r * [email protected]_or_ip:/remote/folder/

Copy single file from remote to local.

scp [email protected]_or_ip:/remote/folder/file.txt  file.txt

If in case of any permission issues you can try

scp -oIdentityFile=keyfile  <LOCAL_FILE> [email protected]_or_ip:/remote/folder/

Method 2: Transfer file using SFTP or Secure FTP

sftp [email protected]_HOST
Connected to YOUR_HOST.
sftp> dir file1 file2 file3
sftp> pwd
Remote working directory: /home/user
sftp> get file2
Fetching /home/user/file2 to file2
/home/user/file2     100% 500KB 900.9KB/s 00:05
sftp> bye

Method 3: Transfer file using rsync

The rsync stands for remote sync and is a tool for remote and local file synchronization.You can also use SSH to secure the rsync session.The given below are the two commands for rsync.

rsync -av --delete --rsh=ssh /path/to/source [email protected]_host_ip:/remote/folder/
rsync -av --delete -e "ssh" /path/to/source [email protected]_host_ip:/remote/folder/

Leave a Reply

Your email address will not be published.Required fields are marked *