A guide for SFTP basic terminal commands.
Connect to Host
- Open up terminal, and connect to host using the command:
1 2 3 4 5
# sftp <username>@<host_name_or_ip_address> $ sftp mrestepa@XXX.XXX.XX.XXX # To use custom port: # sftp -P <custom_port> <username>@<host_name_or_ip_address>
Performing Commands
- To perform commands in remote host, type the commands directly into the terminal as usual.
1
$ sftp> pwd
- To perform commands in local computer, type the commands in the terminal after typing ālā
1
$ sftp> lpwd
Downloading File From Remote to Local
- Navigate into the remote directory where the file is stored.
- Navigate into the local directory where you want to store the downloaded file.
- Type command
get <name of file> .
. The first parameter is the name and location of the file in remote host, and the 2nd parameter is the downloaded file path and name in local.1 2
# get -r <remote_path_and_filename> <local_path_and_filename> $ get samplefile.txt .
- Steps 1 and 2 can be skipped, but include the full path and name of the remote file to download, and full path of local directory to store the file.
- The downloaded file can be renamed in the 2nd parameter by specifying the new name:
1
$ get samplefile.txt newname.txt
Downloading Folder From Remote to Local
- Navigate into the remote directory where the folder is stored.
- Navigate into the local directory where you want to store the downloaded folder.
- Type command
get -r <name of folder> .
. The first parameter is the name and location of the folder in remote host, and the 2nd parameter is the downloaded folder path and name in local.1 2
# get -r <remote_path> <local_path> $ get -r media/ .
- Steps 1 and 2 can be skipped, but include the full path and name of the remote folder to download, and full path of local directory to store the folder.
- The downloaded folder can be renamed in the 2nd parameter by specifying the new name:
1
$ get -r media/ media-backup/
Uploading File From Local to Remote
- Navigate into the local directory where the file is stored.
- Navigate into the remote directory where you want to store the uploaded file.
- Type command
put <name of file> .
. The first parameter is the name and location of the file in local computer, and the 2nd parameter is the uploaded file path and name in remote.1 2
# put <local_path_and_filename> <remote_path_and_filename> $ put samplefile.txt .
- Steps 1 and 2 can be skipped, but include the full path and name of the remote file to download, and full path of local directory to store the file.
- The downloaded file can be renamed in the 2nd parameter by specifying the new name:
1
$ put samplefile.txt newname.txt
Uploading Folder From Local to Remote
- Navigate into the local directory where the folder is stored.
- Navigate into the remote directory where you want to store the uploaded folder.
- Type command
put -r <name of folder> .
. The first parameter is the name and location of the folder in local computer, and the 2nd parameter is the uploaded folder path and name in remote.1 2
# put -r <local_path_and_foldername> <remote_path_and_foldername> $ put -r mediabackup/ .
- Steps 1 and 2 can be skipped, but include the full path and name of the remote file to download, and full path of local directory to store the file.
- The downloaded file can be renamed in the 2nd parameter by specifying the new name:
1
$ put -r mediabackup/ media/