Download Files from Ubuntu Server Using SFTP
Secure File Transfer Protocol (SFTP) is a secure and efficient way to transfer files between a remote Ubuntu Linux server and your local machine. This guide provides a straightforward, step-by-step walkthrough on how to connect to your server and download files using the SFTP command-line interface.
Step 1: Connect to the Remote Server
Open the terminal on your local machine (Linux, macOS, or Windows Git Bash/PowerShell) and run the following command to establish an SFTP connection:
sftp username@your_server_ipReplace username with your actual Ubuntu server username
and your_server_ip with your server’s IP address or domain
name. If you use a non-standard SSH port, add -P followed
by the port number:
sftp -P 2222 username@your_server_ipEnter your password or SSH key passphrase when prompted. Once
connected, your terminal prompt will change to
sftp>.
Step 2: Navigate and Locate Your Files
Before downloading, you need to navigate to the directory containing the file on the remote server, and optionally set the target folder on your local machine.
- View remote directory: Type
pwdto see your current directory on the Ubuntu server. - List remote files: Type
lsto list the files and folders in the current remote directory. - Change remote directory: Use
cd /path/to/remote/folderto navigate to the location of the file you want to download. - View local directory: Type
lpwdto see where downloaded files will be saved on your local machine. - Change local directory: Use
lcd /path/to/local/folderto change the local destination directory.
Step 3: Download the File
To download a file from the remote Ubuntu server to your local
machine, use the get command followed by the filename:
get filename.extIf you want to download the file and rename it during the transfer, specify the new name as the second argument:
get filename.ext new_local_filename.extTo download an entire directory recursively, use the -r
option:
get -r remote_directory_nameStep 4: Disconnect from SFTP
Once your file transfer is complete, close the SFTP connection by typing:
byeOr alternatively:
exit