Transfer File between Remote Server and Local Machine

Transfers file or folder between a remote server (master node), compute node, and client machine can be easily possible with a scp command.

scp or secure copy allows secure transferring of files between between two remote hosts. It uses the same authentication and security as the Secure Shell (SSH) protocol from which it is based. A scp can transfers you both single or multiple files and folders simultaneously. It's simplicity, secure, and fast.


  • Help page of scp
man scp


  • Transfers single file/folder

Here is the normal syntax for single file transfer.

1. From a local machine to a remote machine,

scp  file  user@ip-address:/remote/directory/

2. From a remote machine to a local machine,

scp user@ip-address:/remote/directory/file  /local/directory/


  • Transfers multiple files/folders

For sending multiple files, one can use regular expression "{" and "}" for grouping all files and send them all at the same time.

1. From a local machine to a remote machine,

scp  file1 file2 file3 ...  user@ip-address:/remote/directory/

or

scp  file.*  user@ip-address:/remote/directory/

or

scp  file{1,2,3}  user@ip-address:/remote/directory/

2. From a remote machine to a local machine,

scp user@ip-address:/remote/directory/\{file1,file2,file3\}  /local/directory/


  • Optional

1. Specify port number of remote machine,

Syntax:

scp  -P  <port_number_of_remote>  file1 file2 ... user@ip-address:/remote/directory

Caveat: For scp, you can specify port number using only "-P" (big P).


Rangsiman Ketkaew