Quantcast
Viewing latest article 10
Browse Latest Browse All 10

Secure File Transfer Protocol (SFTP) commands

SFTP:

It’s secure file transfer protocol or SSH file transfer protocol. We can also use FTP and SCP to transfer files to remote server. But SFTP is the most secure and interactive way to transfer files to a remote server. It uses the same authentication method that are available for SSH. You can use username with  password or username with SSH keys to authenticate with remote server. There are several GUI tools are available for SFTP. In this article I will let you know how to use SFTP in command line.

Difference between FTP , SCP and SFTP:

FTP is know as File Transfer Protocol and it’s don’t have any security feature. FTP is interactive but due to lack of security it’s not advisable to use. The default port is 21 for FTP

SCP is know as Secure Copy Protocol. It is secure but not interactive. It uses the same authentication as the SSH. You can only transfer files with this protocol. Because of it is not interactive you can’t issue any commands in the remote machine. The default port is 22 for SCP

SFTP is know as SSH File Transfer Protocol. It’s interactive and you can create file, delete file, change directory using this command in the remote server. The default por i

How to Connect:

sftp --password=password user@sftpserver
or
sftp -o "IdentityFile=keyfile" user@sftpserver

Useful Commands for SFTP:

cd - to change directory in the remote server
lcd - to change directory in the local machine
pwd - to get the current path in the remote server
lpwd - to get the current path in the local machine
ls - to get the directory listing of remote server
lls - to get the directory listing of the local machine
put - to upload a file
mput - to upload multiple files
get - to download file
mget - to download multiple files
exit - to exit from SFTP secession 
! - to exit from SFTP secession

How to use SFTP in shell or bash script:

Using the blow script we can upload a file from our local machine to a defined folder of the remote machine. If you want to upload multiple file then you can use

mput
 command instead of
put
 .
#!/bin/bash

(
echo "
ls -l
cd /home/user/backup
put file.txt
!
"
) | -n sftp user@sftpserver

 


Viewing latest article 10
Browse Latest Browse All 10

Trending Articles