How to Copy a remote file to local using SFTP command?


If you are provided with a remote host and asked to copy a file from there to your local computer, you can make use of the SFTP Get command, let's take a look,

Syntax: get {remote-path/to/the/file} {destination/path}

Example:
sftp> get /pub/example/readme.txt myRemoteFiles           
Fetching /pub/example/readme.txt to myRemoteFiles

/pub/example/readme.txtn.   100%  405     0.9KB/s   00:00    

sftp> 

The easiest way is to first be on the path where you want to copy this file to and connect to the remote server using SFTP and then use dot (.) to copy the file in the current location you are in.

Example:
sftp> get /pub/example/readme.txt .           
Fetching /pub/example/readme.txt to .

/pub/example/readme.txt 100%  405     0.9KB/s   00:00    

sftp> 

Copy a remote file to local using SFTP command
Copy a remote file to local using SFTP command
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.