An SFTP server can be accessed with a graphical client or through SFTP commands. SFTP stands for Secret File Transfer Protocol or Secure FTP. It uses the Secure Shell protocol (SSH) for file transfer so it is also termed the SSH File Transfer Protocol. It is different from the standard File Transfer Protocol (FTP) because it encrypts commands as well as data. This prevents sensitive information such as passwords and credit card numbers from leaking over the internet.
SFTP uses a different protocol for transfer. So an FTP client can not be used for transferring files through the SFTP protocol. Similarly an SFTP client cannot be used for FTP.
Graphical SFTP Clients
Graphical clients are fairly simple to use. Files can be transferred by the drag and drop method. The hosts name has to be entered when the program is run. After that a username and password has to be fed in to access or transfer files. WinSCP is a common client for SFTP protocol. Similarly CyberDuck is used on a Macintosh PC.
Command line SFTP
SFTP can be used through the Command Prompt on a UNIX account or UNIX workstation. The MAC OS X also supports it. The first step is to connect to the remote host and provide log in details. The host can be a computer or server to which files can be transferred or the existing files can be accessed. A few common SFTP commands have been given below and an outline of the procedure follows.
Command | Function |
cd | Changes directory on server |
dir or ls | List files on server |
exit or quit | Ends connection |
get | Copies files |
help | Provides help on SFTP commands |
lcd | Changes directory on computer |
lmkdir | Creates a new directory |
Enter the following line at the UNIX prompt to start the session. This is a commonly used SFTP command.
sftp username@host
If ‘abc’ is the username and ‘xyz.org’ is the host name, then the command to be entered is
sftp abc@xyz.org
Provide the password. The SFTP prompt will now be displayed. The standard file and directory UNIX commands have to be used to give commands to the remote host and the local host, which is the computer you would be using. Use an exclamation mark before each command.
The default directory for sending and receiving files will be the local or working directory. This can be changed if a different location has to be specified for the purpose. As an example, ‘Incoming’ is a folder on the local directory in which all files have to be received.
Create the ‘Incoming’ folder by using the !mkdir UNIX command.
Change the default folder to the new ones through the lcd command.
sftp> ! mkdir INCOMING
sftp> ! lcd INCOMING
The syntax for copying files on the local computer.
get filename
If info is the file name, type the following SFTP command.
get info. The put command can be used if a file has to be downloaded from the server.
put local-path-to-file remote-path
The connection can be closed with the SFTP command quit.
These are some of the most common SFTP commands. I will describe some more in the nearest future, when I have some spare time.