How to use SFTP in command line for file transfer

SFTP is a FTP like file transferring protocol with additional security measures. Additional security measures put in place by connecting through SSH. You can log in to the SFTP server through command line and upload, download manage files in an interactive way. SFTP has been integrated to many GUI also (WinSCP, Filezilla, FireFTP etc). In this article, I’m going to discuss few useful SFTP commands which you will use often.

How to Connect

You can connect to the SFTP by this command using the default port (22)
SFTP [sftp_user_name]@[server_ip/server_name]
sftp default port

If you are using a custom port, bellow command will help to connect.
SFTP -P [port] [sftp_user_name]@[server_ip/server_name]
SFTP With Custom Port

Few Important SFTP Commands

You can issue regular linux commands to run it on remote server and the regular commands with prefix ‘l’ to run it on local machine. I have listed few of them which you will be frequently using.

? / helpList all the available commands
cdChange directory (remote)
lcdChange directory (local)
pwdShowing present working directory (remote)
lpwdShowing present working directory (local)
lsListing files (remote)
llsListing files (local)
put [file name]Upload file from local to remote
mput [pattern].extUpload files following similar naming pattern
or same extension.
get [file name]Download file from remote server to local.
mkdir [dir name]Creating a directory on remote
mkdir [dir name]Creating a directory on local
!Exit from the sftp command line.

SFTP is a simple tool. But this can be securely used to administrating servers and for file transferring. Hope this article helped you to get a rough idea and essential knowledge to manage your SFTP with console.