How To Use SFTP Command To Transfer Encrypted Files
How to use SFTP Command
SFTP stands for Secure File Transfer Protocol. Widely we use ftp for transferring data and files remotely. To add more security reason we go for SFTP. It runs over the ssh protocol using default port 22. This tutorial explains the SFTP command.
Syntax
sftp username@remote_hostname_or_IP
1.Start and connect SFTP.
The following command is used to connect the remote machine.
[root@linuxhelp Desktop]# sftp root@192.168.5.98 Connecting to 192.168.5.98... root@192.168.5.98' s password: sftp>
2. Check Present Working Directory on Remote Machine.
Using the pwd command we can check present working directory on remote machine.
sftp> pwd
Remote working directory: /root/Desktop
In SFTP we can also check local machine’ s present working directory using lpwd.
sftp> lpwd
Local working directory: /root/Desktop
3.Listing Files
We can list the files in remote machine by using ls command.
sftp> ls
copy.txt~ file1 file2 file3 file4
If you want to check local machine files you can use lls command.
sftp> lls
copy.txt~ doc1 doc2 doc3 doc4
4.Upload single file
put command is used to upload files from local machine to remote machine.
sftp> put textsample.txt
Uploading textsample.txt to /root/textsample.txt
textsample.txt 100% 10KB 10.2KB/s 00:00
5.Upload multiple File
To upload file use mput command.
sftp> mput *.txt
Uploading text1.txt to /root/text1.txt
text1.txt 100% 6404 6.3KB/s 00:00
Uploading text2.txt to /root/text2.txt
text2.txt 100% 4046 4.0KB/s 00:00
Uploading text3.txt to /root/text3.txt
text3.txt 100% 8433 8.2KB/s 00:00
Here all the .txt files are uploaded from local machine to remote machine.
6.Download files
If you want to download file from remote machine to local machine use get command.
sftp> get file1
Fetching /root/Desktop/file1 to file1
/root/Desktop/file1 100% 6394 6.2KB/s 00:00
If you want to download multiple files use mget command.
sftp> mget *.txt
Fetching /root/Desktop/down1.txt to down1.txt
/root/Desktop/down1.txt 100% 6394 6.2KB/s 00:00
Fetching /root/Desktop/down2.txt to down2.txt
/root/Desktop/down2.txt 100% 4040 4.0KB/s 00:00
Fetching /root/Desktop/down3.txt to down3.txt
/root/Desktop/down3.txt 100% 6394 6.2KB/s 00:00
Fetching /root/Desktop/textsample.txt to textsample.txt
/root/Desktop/textsample.txt 100% 10KB 10.2KB/s 00:00
7.Change Working Directory
cd command is use to change the directory on remote machine.
sftp> pwd Remote working directory: /root sftp> cd /root/Desktop sftp> pwd Remote working directory: /root/Desktop
If you want to change the directory in local machine you can use lcd command.
sftp> lpwd Local working directory: /root/Desktop sftp> lcd /root/Desktop/localdir sftp> lpwd Local working directory: /root/Desktop/localdir
8.Create Directory
To create a directory use mkdir command in remote machine.
sftp> ls copy.txt~ down1.txt down1.txt~ down2.txt down2.txt~ down3.txt down3.txt~ file1 file1~ textsample.txt sftp> mkdir remodir sftp> ls copy.txt~ down1.txt down1.txt~ down2.txt down2.txt~ down3.txt down3.txt~ file1 file1~ remodir textsample.txt
If you want to create directory on local machine use lmkdir.
sftp> lls copy.txt~ doc1~ down2.txt file1 text1.txt text2.txt text3.txt textsample.txt doc1 down1.txt down3.txt localdir text1.txt~ text2.txt~ text3.txt~ sftp> lmkdir localfolder sftp> lls copy.txt~ doc1~ down2.txt file1 localfolder text1.txt~ text2.txt~ text3.txt~ doc1 down1.txt down3.txt localdir text1.txt text2.txt text3.txt textsample.txt
9.Remove file or Directory
rm command helps to remove a file on remote machine.
sftp> rm file1
Removing /root/Desktop/file1
rmdir command is used to remove the directory on remote machine.
sftp> ls copy.txt~ down1.txt~ down2.txt down2.txt~ down3.txt down3.txt~ file1~ remodir textsample.txt sftp> rmdir remodir sftp> ls copy.txt~ down1.txt~ down2.txt down2.txt~ down3.txt down3.txt~ file1~ textsample.txt
10.Exit SFTP
If you want to leave these SFTP terminal use exit command.
sftp> exit
[root@linuxhelp Desktop]#
Comments ( 0 )
No comments available