June 8

Linux: SFTP Commands

Typical SFTP session:

sftp yoursite.com
(The SFTP server now requests username and password information.)
cd project/data
(On the remote machine, move to the project/data subdirectory.)
ls
(Get a list of the files in the current remote directory.)
get oldstuff.txt
(Copy the file oldstuff.txt from the remote directory.)
get folder/olderstuff.txt
(Also copy the file olderstuff.txt, which is in a subdirectory
on the remote machine.)
lcd ..
(Move up one level in the local directory.)
lls
(Get a directory of the current local directory.)
put newstuff.txt currentstuff.txt
(Copy the local file newstuff.txt to the remote directory,
but rename the copy currentstuff.txt.)
quit

If you have many files to move, the mget and mput commands may help you:

mget *.C
(Make a local copy of all the remote files with extension “.C”)
mput file.??
(Make a remote copy of all the local files whose names begin with
file. followed by two characters.)

To avoid being asked to confirm every single transfer, you might try issuing the sftp command prompt first.

In some cases, the commands binary and text may be useful, if you wish to transfer binary or text files, especially when the remote computer has a different architecture than the local one. This is especially an issue when transferring text files between a Macintosh or PC and a Unix machine.

List of SFTP commands (SFTP will abort if any of the following
commands fail):


get [flags] remote-path [local-path]

Retrieve the remote-path and store it on the local machine. If the
local path name is not specified, it is given the same name it has on the
remote machine.

put [flags] local-path [local-path]

Upload
local-path
and store it on the remote machine. If the remote path name is
not specified, it is given the same name it has on the local machine.

rename oldpath newpath

Rename remote file from
oldpath
to newpath.

ln oldpath newpath

Create a symbolic link from
oldpath
to newpath.

rm path

Delete remote file specified by path.

lmkdir path

Create local directory specified by path.

bye

Quit sftp.

exit

Quit sftp.

quit

Quit sftp.

cd path

Change remote directory to path.

lcd path

Change local directory to path.

ls [path]

Display remote directory listing of either path
or current directory if path is not specified.

pwd

Display remote working directory.

rmdir path

Remove remote directory specified by path.

chgrp grp path

Change group of file path to
grp
. grp must be a numeric GID.

chmod mode path

Change permissions of file path
to mode.

chown own path

Change owner of file path to
own
. own must be a numeric UID.

symlink oldpath newpath

Create a symbolic link from
oldpath to newpath.

mkdir path

Create remote directory specified by path.

lls [ls-options [path]]

Display local directory
listing of either path or current directory if path is not
specified.

lpwd

Print local working directory.

lumask umask

Set local umask to umask.

! command

Execute command in local shell.

!

Escape to local shell.

?

Synonym for help.

help

Display help text

By: UMBC


Copyright 2021. All rights reserved.

Posted June 8, 2012 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B