How To Run SFTP Commands To Transfer Files | ITGUYAKAY

In our previous post, we have seen that how we can setup and configure SFTP Server in Redhat/CentOS. In this guide we will see some basic operations of sftp command e.g upload/download files over SFTP server, lists/browse files on server, establish connection using custom port, file compression over file transfer etc. There are many GUI tools available such as FileZilla which can use to accomplish this task but we will see how can we perform these tasks over command line. Lets start...

SFTP File Transfer Commands

Note: It is recommended to use SSH key for password authentication. Please visit previous post for more details.

Always use --help/ -h or man pages for any type of help

1) Connect To SFTP server

sftp username@server_ip/hostname

Example:

2) Connect Using Custom Port Number

sftp -P port-number username@server_ip/hostname

Example:

Note: You can use -C option flag to enable compressions for your SFTP connection

3) Check The Current Path After Login To Remote SFTP Server

pwd

4) List Files and Directories In Remote SFTP Server

ls -l

Example:

5) Check The Current Path Of Local Host Machine

lpwd

6) List Files and Directories In local host machine.

lls -l

7) Change Directory Path On Remote SFTP Server

cd /path

8) Change Directory Path On Local Host Machine

lcd /path

9) Creating Directory On Remote SFTP server

mkdir /path/to/directory

10) Creating Directory On Local System

lmkdir /path/to/directory

11) Download Any File From Remote SFTP Server

get [option] [remote_path] [local_path]

Example:

There are some option flags that you can use with get command, described as below.

1) If the -a flag is specified, then attempt to resume partial transfers of existing files.

2) If the -f flag is specified, then fsync will be called after the file transfer has completed to flush the file to disk

3) If the -p flag is specified, then full file permissions and access times are copied too.

4) If the -R flag is specified then directories will be copied recursively

Examples:1

Examples:2

12) Upload Files/Directories To Remote SFTP File Server.

put [option] [local_path] [remote_path]

The option flags are same as get command has.

Example:

13) Check Disk Utilization Summary

df -h

Example:

14) Some Keyboard shortcuts

? sign can be used instead of typing "help" to get help.

! sign can be used to get local interactive shell prompt.

!`command` sign can be used to execute any command on local machine without adding l prefix.

Example:

15) Exit SFTP

quit #or exit

Post a Comment

0 Comments