File transfer protocol (FTP) was a widely used protocol for remotely transferring files or data in an unencrypted format that is not a secure way of communication.
How we all know File transfer protocol is not at all secure, as all transmissions are in clear text and the data can be read by anyone on the network when the packets are sniffed.
So basically, FTP can be used in limited cases or on the networks you trust. Over time, Secure Copy (SCP) and Secure Shell (SSH) addressed this security ambiguity and added an encrypted layer of security as data is transferred between remote computers.
[ You might also like: Best Command-Line FTP Clients for Linux ]
SFTP (Secure File Transfer Protocol) it’s spilling over SSH Protocol on standard port 22nd by default to establish a secure connection. SFTP has been integrated into many GUI Tools (FileZilla, WinSCP, FireFTP, Etc.).
Security warnings: Please do not open SSH Harbor (Safe SHell) worldwide as this would be a security breach. You can only open for a specific IP address from which you transfer or manage files on the remote system or vice versa.
- How to secure and harden the OpenSSH server
- How to change the SSH port on Linux
- How to use Rsync to sync files using a non-standard SSH port
- 5 Best Practices for Securing and Protecting SSH Servers
- 10 examples of wget commands in Linux
This article will guide you to 10 examples of sftp commands to use via the interactive command line interface in the Linux terminal.
1. How to connect to SFTP
By default, the same SSH protocol is used to authenticate and establish an SFTP connection. To start an SFTP session, enter the user name and remote host name or IP address at the command prompt. After successful authentication you will see a shell with a sftp> prompt.
[[email protected] ~]# sftp [email protected] Connecting to 22.214.171.124... [email protected]'s password: sftp>
2. Get help
Once you are in sftp prompt, check the available commands by typing ‘?‘ or ‘help‘at the command prompt.
sftp> ? Available commands: cd path Change remote directory to 'path' lcd path Change local directory to 'path' chgrp grp path Change group of file 'path' to 'grp' chmod mode path Change permissions of file 'path' to 'mode' chown own path Change owner of file 'path' to 'own' help Display this help text get remote-path [local-path] Download file lls [ls-options [path]] Display local directory listing ln oldpath newpath Symlink remote file lmkdir path Create local directory lpwd Print local working directory ls [path] Display remote directory listing lumask umask Set local umask to 'umask' mkdir path Create remote directory put local-path [remote-path] Upload file pwd Display remote working directory exit Quit sftp quit Quit sftp rename oldpath newpath Rename remote file rmdir path Remove remote directory rm path Delete remote file symlink oldpath newpath Symlink remote file version Show SFTP version !command Execute 'command' in local shell ! Escape to local shell ? Synonym for help
3. Check the current working directory
The command ‘lpwd‘is used to denote the Local current working directory while using the pwd command to create the remote control Working directory.
sftp> lpwd Local working directory: / sftp> pwd Remote working directory: /tecmint/
- lpwd – Print the current directory on your system
- pwd – Print the current directory on the FTP server
4. List files with sFTP
List files and directories on a local and remote system FTP server.
On remote control
5. Upload the file with sFTP
Store single or multiple files on the remote system’s FTP server.
sftp> put local.profile Uploading local.profile to /tecmint/local.profile
6. Upload multiple files with sFTP
Creation of multiple files on the remote system’s FTP server.
sftp> mput *.xls
6. Download files with sFTP
Retrieve single or multiple files on a local system.
sftp> get SettlementReport_1-10th.xls Fetching /tecmint/SettlementReport_1-10th.xls to SettlementReport_1-10th.xls
Get multiple files on a local system.
sftp> mget *.xls
note: As we can see by default Order received Download the file in the local system with the same name. We can download remote files with a different name by adding the name at the end. (This only applies when downloading the individual file).
7. Change of directory in sFTP
Change from one directory to another directory in local and remote locations.
On remote control
sftp> cd test sftp>
sftp> lcd Documents
8. Create directories with sFTP
Create new directories in local and remote locations.
sftp> mkdir test
sftp> lmkdir Documents
9. Remove directories with sFTP
Remove a directory or file on a remote system.
sftp> rm Report.xls
sftp> rmdir sub1
note: To remove / delete a directory from a remote location, the directory must be empty.
10. Exit the sFTP shell
The ‘!‘Command puts us in a local shell from which we can execute Linux commands. Type ‘exit‘Command where we can see sftp> prompt return.
sftp> ! [[email protected] ~]# exit Shell exited with status 1 sftp>
the SFTP is a very useful tool for managing servers and transferring files to and from (Local and remote control). We hope these tutorials will help you use the. to understand SFTP to a certain degree.