[‘
File Transfer Protocol (FTP) was a widely used protocol to transfer files or data remotely in an unencrypted format which is not a secure way to communicate.
n
As we all know that File Transfer Protocol is not at all secure because all transmissions happen in clear text and the data can be readable by anyone during sniffing the packets on the network.
n

n
So, basically, FTP can be used in limited cases or on the networks that you trust. Over the period of time, SCP (Secure Copy) and SSH (Secure Shell) addresses this security ambiguity and added an encrypted secure layer while transferring data between remote computers.
n
[ You might also like: Best Command-Line FTP Clients for Linux ]
n
SFTP (Secure File Transfer Protocol) runs over SSH protocol on standard port 22 by default to establish a secure connection. SFTP has been integrated into many GUI tools (FileZilla, WinSCP, FireFTP, etc.).
n
Security Warnings: Please don’t open the SSH port (Secure SHell) globally as this would be a security breach. You can only open for specific IP from where you are going to transfer or manage files on the remote system or vice versa.
n
- n
- How to Secure and Harden OpenSSH Server
- How to Change SSH Port in Linux
- How to Sync Files Using Rsync with Non-standard SSH Port
- 5 Best Practices to Secure and Protect SSH Server
- 10 Wget Command Examples in Linux
n
n
n
n
n
n
This article will guide you to 10 sftp command examples to use through the interactive command-line interface in the Linux terminal.
n
1. How to Connect to SFTP
n
By default, the same SSH protocol is used to authenticate and establish an SFTP connection. To start an SFTP session, enter the username and remote hostname or IP address at the command prompt. Once authentication is successful, you will see a shell with an sftp> prompt.
n
[[emailxa0protected] ~]# sftp [emailxa0protected]rnrnConnecting to 27.48.137.6...rn[emailxa0protected]'s password:rnsftp>
n
2. Getting Help
n
Once, you are in the sftp prompt, check the available commands by typing ‘?‘ or ‘help‘ at the command prompt.
n
sftp> ?rnAvailable commands:rncd path Change remote directory to 'path'rnlcd path Change local directory to 'path'rnchgrp grp path Change group of file 'path' to 'grp'rnchmod mode path Change permissions of file 'path' to 'mode'rnchown own path Change owner of file 'path' to 'own'rnhelp Display this help textrnget remote-path [local-path] Download filernlls [ls-options [path]] Display local directory listingrnln oldpath newpath Symlink remote filernlmkdir path Create local directoryrnlpwd Print local working directoryrnls [path] Display remote directory listingrnlumask umask Set local umask to 'umask'rnmkdir path Create remote directoryrnput local-path [remote-path] Upload filernpwd Display remote working directoryrnexit Quit sftprnquit Quit sftprnrename oldpath newpath Rename remote filernrmdir path Remove remote directoryrnrm path Delete remote filernsymlink oldpath newpath Symlink remote filernversion Show SFTP versionrn!command Execute 'command' in local shellrn! Escape to local shellrn? Synonym for help
n
3. Check Present Working Directory
n
The command ‘lpwd‘ is used to check the Local present working directory, whereas the pwd command is used to check the Remote working directory.
n
sftp> lpwdrnLocal working directory: /rnsftp> pwdrnRemote working directory: /tecmint/
n
- n
- lpwd – print the current directory on your system
- pwd – print the current directory on the ftp server
n
n
n
4. Listing Files with sFTP
n
Listing files and directories in local as well as a remote system ftp server.
n
On Remote
n
sftp> ls
n
On Local
n
sftp> lls
n
5. Upload File Using sFTP
n
Put single or multiple files in remote system ftp server.
n
sftp> put local.profilernUploading local.profile to /tecmint/local.profile
n
6. Upload Multiple Files Using sFTP
n
Putting multiple files on in remote system ftp server.
n
sftp> mput *.xls
n
6. Download Files Using sFTP
n
Getting single or multiple files in a local system.
n
sftp> get SettlementReport_1-10th.xlsrnFetching /tecmint/SettlementReport_1-10th.xls to SettlementReport_1-10th.xls
n
Get multiple files on a local system.
n
sftp> mget *.xls
n
Note: As we can see by default with get command download file in local system with the same name. We can download remote files with a different name by specifying the name at the end. (This applies only while downloading the single file).
n
7. Switching Directories in sFTP
n
Switching from one directory to another directory in local and remote locations.
n
On Remote
n
sftp> cd testrnsftp>
n
On Local
n
sftp> lcd Documents
n
8. Create Directories Using sFTP
n
Creating new directories on local and remote locations.
n
sftp> mkdir test
n
sftp> lmkdir Documents
n
9. Remove Directories Using sFTP
n
Remove directory or file in a remote system.
n
sftp> rm Report.xls
n
sftp> rmdir sub1
n
Note: To remove/delete any directory from a remote location, the directory must be empty.
n
10. Exit sFTP Shell
n
The ‘!‘ command drops us in a local shell from where we can execute Linux commands. Type ‘exit‘ command where we can see sftp> prompt return.
n
sftp> !rnrn[[emailxa0protected] ~]# exitrnShell exited with status 1rnsftp>
n
Conclusion
n
The SFTP is a very useful tool for administrating servers and transferring files to and from (Local and Remote). We hope this tuts will help you to understand the usage of SFTP to some extent.
n
‘]