7 Useful SFTP Command Line Examples

We are all familiar with the FTP protocol, and if you are reading this article, you have probably used it to transfer files on a virtual server and on a local computer. FTP is a very simple sv protocol, but it is also very insecure. All transmissions, including username and password, are transmitted unencrypted and no type of security or encryption is used in the transmission of data. This means that all data can be read by someone, they can intercept the transmission. Fortunately, there is a great replacement for FTP, SFTP.

SFTP stands for Secure File Transfer Protocol and relies on SSH. SFTP allows users to transfer data over a connection that is secured using the well-known secure protocol (SSH) Shell. SFTP is also faster and uses less data than FTP. Therefore, we strongly recommend using SFTP instead of FTP whenever possible. You can transfer files between machines using some of the popular SFTP clients such as FileZilla, Cyberduck, or WinSCP. You can also do this directly from the Linux command line.

In this article, we will list and explain some of the most popular and useful SFTP commands. They are great for beginners – easy to understand, and useful for everyday server tasks.

1. Connecting to an SFTP server

You can connect to a remote server via SFTP with the following command

sftp  [email protected]_Address

[email protected]_Address' password:
Connected to IP_Address.

You can also use the hostname instead of the IP address.

We already mentioned that SFTP uses the same protocol as SSH, so if SSH is not listening on the default port 22, you can specify the port in the command

sftp -oPort=3456 [email protected]_Address

Where ‘3456’ is the port number you are using.

2. List of all files in the current directory

Using the Ls command you can get a list of all files and directories in the current working directory

sftp> ls
directory directory1  file  file.txt file.zip

You can also view the list of files on the local system

sftp> lls

3. Browse directories

To find the current working directory when using local server

sftp> pwd
Remote working directory: /home/furious

for the local server using the following command

sftp> lpwd
Local working directory: /

You can easily change the working directory in SFTP. To use a remote server

sftp? cd directory

and also for using local server

sftp> lcd directory

4. Upload files and directories using put command

You can download one or more files or directories from local to remote computer.

sftp> put filename

Upload multiple files using the following command

sftp> mput file1 file2 file3

Upload a directory on the remote server, you have to create a destination directory on the remote server and then start uploading

sftp> mkdir directory
sftp> put -r directory/

5. Downloading files and directories using the GET command

Download one file from a remote computer to a local computer

sftp> get file

or download multiple files using ‘mget’ command

sftp> mget file1 file2 file3

Download the directory and all its contents with the following command

sftp> get -r directory

6. Creating and deleting directories

Create a new directory on the remote server

sftp> mkdir newdirectory

Create a new directory on your local server

sftp> lmkdir newdirectory

7. Getting help

You can find all SFTP commands with a short description by executing ‘help’ or ‘?’.

sftp> ?

Available commands:
bye                                Выход sftp
cd path                            Изменить удаленный каталог 'path'
chgrp grp path                     Изменить группу файлов 'path' в 'grp'
chmod mode path                    Изменение разрешения файла 'path' на 'mode'
chown own path                     Сменить владельца файла 'path' to 'own'
df [-hi] [path]                    Отображение статистики для текущей директории или
файловой системы, содержащая 'path'
exit                               Выход sftp
get [-Ppr] remote [local]          Загрузка файлов
reget remote [local]            Возобновить загрузку файла
help                               Показать справку
lcd path                           Изменить локальный каталог на 'path'
lls [ls-options [path]]            Показать список локального каталога
lmkdir path                        Создать локальный каталог
ln [-s] oldpath newpath            симлинк на удаленный каталог (-s for symlink)
lpwd                               Напечатать локальный рабочий каталог
ls [-1afhlnrSt] [path]             Показать список удаленного каталога
lumask umask                       Установка локально umask to 'umask'
mkdir path                         Создать удаленный каталог
progress                           Показывать индикатор прогресса
put [-Ppr] local [remote]          Загрузить файл
pwd                                Показать удаленный рабочий каталог
quit                               Выйти с sftp
rename oldpath newpath             Переименовать удаленный файл
rm path                            Удалить удаленный файл
rmdir path                         Удалить удаленный каталог
symlink oldpath newpath            Symlink удаленного файла
version                            Показать версию SFTP
!command                           Выполнить 'command' в локальной оболочке
!                                  Выйти в локальную оболочку
?                                  Синоним помощи

Sidebar