|
sftp.exe
The sftp client is used to connect to any SFTP server. It operates much like the standard ftp client, but cannot be used to connect to a ftp server. With the logging and batch file options, sftp sessions can be completely automated.
Usage
sftp [-1vCp] [-A Password] [-b batchfile] [-L logfilename] [-osshopt=value] [user@]host[:file [file]]
The host must be given on the command line. The current interactive username will be used unless a user id is passed on the command line. This is done by adding the desired username to the hostname with the @ symbol. For example to connect to sftpserver as administrator, connect with sftp administrator@sftpserver
Options
|
1
|
use the SSH1 protocol
|
|
v
|
verbose mode for debugging
|
|
C
|
use compression
|
|
p
|
use transfer timestamp on new files
|
|
A Password
|
use password to logon to sftp server
|
|
b batchfile
|
automation file - list desired commands to process after connected
|
|
L logfilename
|
allows commands and responses to be logged to file logfilename
|
|
o sshoptions
|
Options that should be passed to the ssh client. Options that are allowed are defined in the config file of the ssh client. See SSH Configuration File for more info.
Special note that there should not be any space between the o and the option.
The o option can be used as often as necessary to pass all the desired ssh options.
|
Available Commands
|
!
|
Escape to the shell
|
|
!command
|
Execute 'command' in local shell
|
|
cd
|
Change remote working directory
|
|
chmod
|
Change file permissions of remote file
|
|
chown own path
|
Change owner of file 'path' to 'own'
|
|
chgrp grp path
|
Change group of file 'path' to 'grp'
|
|
close
|
Close the current connection
|
|
exit
|
Terminate session and exit
|
|
get/mget [-p]
|
Receive one/multiple file. Add the -p option to treat the transfer timestamp differently than default
|
|
help
|
Show local help information
|
|
lcd
|
Change local working directory
|
|
lls/ldir
|
Display local directory listing
|
|
ln oldpath newpath
|
Symlink remote file
|
|
lmkdir path
|
Create local directory
|
|
lpwd
|
Show local working directory
|
|
ls
|
List contents of remote directory
|
|
lumask umask
|
Set local umask to 'umask'
|
|
mkdir
|
Make directory on the remote machine
|
|
put/mput
|
Send one/multiple file
|
|
pwd
|
Show working directory on remote machine
|
|
open [user@]<host>[#port]
|
Connect to sftp server
|
|
quit
|
Terminate session and exit
|
|
rename
|
Rename file
|
|
rmdir
|
Remove directory on the remote machine
|
|
rm path
|
Delete remote file
|
|
symlink oldpath newpath
|
Symlink remote file
|
|
version
|
Show SFTP version
|
|
?
|
Show local help information
|
Status Messages
Each command processed by sftp will return an response. The codes for these responses are:
000 Success 001 End of file reached 002 File or Directory not found 003 Permission Denied 004 SFTP Internal Error 005 SFTP Protocol Error 006 No SFTP Connection 007 SFTP Connection Dropped 008 Unsupported SFTP Command
Each command will also list as STARTED and COMPLETED. These responses are designed for easy parsing to read log files for successful automated sessions.
Examples
The most common sftp file transfers involves using a key for authentication. To pass a key for authentication use the -o option:
sftp -oidentityFile2=key_name user@server
SFTP on a different port can also be done with the -o option:
sftp-oport=portNumber source_file user@server
To automate a sftp session, use the -b option to assign a batch file and -L option to log the batch file output.
sftp -oidentityFile2=key_name -L batch.output -b batch.txt user@servername
The batch file should contain the commands just as they would be typed by the user, such as
cd \upload put file1 cd \download mget * exit
If the open command is used within the batch file, then the command line should not contain any other parameters. The ssh configuration file for the user running the batch should be used.
For example, the above batch file using the open command would be:
open user@servername cd \upload put file1 cd \download mget * exit close
and the command line would be:
sftp -b batchfile.txt
To use the above file with key authentication, the key should be assigned in the configuration file, config, located in the PragmaSSH subdirectory of the %APPDATA% directory of the user running the batch file.
See also:
Command Line Proxy Support
|