put local.profile
sftp -oPort=2222 [email protected]
Related Articles:
sftp> mget *.xls
To delete a file, use the rm command inside the sFTP prompt. For example, if you want to remove a file named Report.xls
from the current remote directory, run:
Local working directory: /
sftp> pwd
Remote working directory: /tecmint/
lpwd
helps you verify where files will be downloaded to.pwd
helps you confirm where files will be uploaded from.
The command lpwd
(local print working directory) is used to display your current local directory on your own machine from which you’re working. On the other hand, the command pwd
(print working directory) shows your current directory on the remote server.
sftp user@remote_host
10. Exit sFTP Shell
bye
Or
exit
sftp> get SettlementReport_1-10th.xls
You can access sFTP from the Linux terminal using the sftp
command, which often pre-installed on most Linux distributions.
sftp> lpwd
8. Creating Directories Using sFTP
exit
rmdir sub1
sftp> ls -l
If you’re inside an sFTP session and need to temporarily drop into your local Linux shell without disconnecting from the remote sFTP session, you can use the !
command, which lets you run local Linux commands directly from within the sFTP environment.
To change the remote directory (the directory on the server you’re connected to), use the cd command followed by the desired path.
For example:
3. Listing Files with sFTP
lcd /home/user/documents
cd /var/www/html
put index.html
5. Download Files Using sFTP
sftp> ?
2. Check Present Working Directory
Once authentication is successful, you will see a shell with the sftp>
prompt.
lmkdir Documents
Next, copy your public key to the remote server using:
sftp> ls
Security Warning: Please don’t expose the SSH (Secure Shell) port to the public internet, as this poses a security risk. Instead, allow access only from specific IP addresses that will be used to transfer or manage files on the remote system.
[ You might also like: Best Command-Line FTP Clients for Linux ]
Because of this, FTP should only be used in limited cases or on networks you fully trust. Over time, protocols like SCP (Secure Copy) and SSH (Secure Shell) have addressed these security concerns by introducing encrypted layers for securely transferring data between remote systems.
ssh-copy-id user@remote_host
rm Report.xls
sftp> cd test
As we all know, FTP is not secure because all transmissions occur in clear text, which means that anyone sniffing network packets can easily read the data.
exit
Shell exited with status 1
sftp>
By default, the get
command downloads the file using its original name. However, if you wish to save the file under a different name locally, you can specify a second argument with the desired name.
6. Renaming Files While Downloading Using sFTP
sftp> get SettlementReport_1-10th.xls Report_Jan.xls
sftp> !
rmdir failed: Directory not empty
Use sFTP with SSH Keys (No Password Prompt)
ls -l
which sftp
This article walks you through real-world sFTP command examples, from logging in and navigating directories to uploading and downloading files. We’ll also cover batch transfers, scripting, and automation tips using sFTP.
So before removing any directory, make sure it’s empty. Otherwise, the rmdir
command will fail with an error like:
Once you’ve connected to the remote server using the sftp command, you can use the put
command to upload a file. For example, let’s say you have a file called local.profile
on your local machine, and you want to transfer it to the remote server.
Here’s how they look in an active sFTP session:
Uploading local.profile to /home/username/local.profile
sftp> lcd Documents
sFTP (Secure File Transfer Protocol) is a part of the SSH protocol suite that runs over the SSH protocol on the standard port 22
by default to establish a secure connection. SFTP has been integrated into many GUI tools such as FileZilla, WinSCP, and FireFTP.
sftp> pwd
sftp> lls -l
Once you’re connected to a remote server using sFTP, you’ll often need to browse through directories to check the available files on remote system and on your local machine.
sftp [email protected]
mput *.txt
File Transfer Protocol (FTP) was once a widely used method for transferring files or data remotely. However, it transmits information in an unencrypted format, making it an insecure way to communicate.
On the other hand, if you want to create a directory on your local machine while inside the sFTP session, use the lmkdir
command:
To list files on the remote server, simply use the ls command, which will show the contents of the current directory on the remote host.
ssh-keygen -t rsa -b 4096
You should see output similar to:
mkdir test
By default, the same SSH protocol is used to authenticate and establish an SFTP connection. To start an SFTP session, enter the username and the remote hostname or IP address at the command prompt.
sftp> lls
sftp> bye
Conclusion
The SFTP is a very useful tool for administrating servers and transferring files to and from (Local and Remote). We hope these examples will help you to understand the usage of SFTP to some extent.