Technical Notes |
|
Both the scp2 (secure copy) and sftp (secure FTP) file transfer client utilities provide secure encrypted authentication and data transfer over SSH2. This technical note describes how to establish an authentication method that can be automated, how to create a batch file of sftp file transfer commands, and then how to issue an sftp2 command that uses the authentication method and batch file as parameters.
For more information about the difference between scp2 and sftp, see Technical Note 1918.
To automate an sftp file transfer, you must first set up an authentication method that does not require user input, such as Public Key Authentication with an empty passphrase. To use this method, generate a key pair on the client with no passphrase and upload the public key to the .ssh2 folder on the secure server.
Use a text editor, such as Notepad, to create a text batch file that contains the sftp file transfer commands you want to automate. You will call this file when you issue the sftp2 command.
Note: We recommend saving this batch file with a .txt extension instead of the .bat extension.
The table below lists some frequently used sftp commands. For a full list of commands and their syntax, type help at the sftp prompt, or see "using sftp2" in the F-Secure SSH help.
| Sftp Command |
Function |
lcd |
Changes the current local working directory |
cd |
Changes the current remote working directory |
mkdir <directory> |
Creates the directory specified in <directory> |
lmkdir <directory> |
Locally creates the directory specified in <directory> |
get <file name(s)> |
Transfers the specified file(s) from the remote host to the local workstation |
put <file name(s)> |
Transfers the specified file(s) to the remote host from the local workstation |
ascii |
Changes the file transfer mode to ascii. An option parameter sets the new line convention to DOS, UNIX, or Mac |
binary |
Changes the file transfer mode to binary |
quit |
Quits sftp |
The following is a sample batch file that copies the remote file /home/user/test.txt to the local C:\filetransfer\get folder, and then copies the local file C:\filetransfer\put\test2.txt to the host's /home/user directory.
cd /home/userlcd “C:\filetransfer\get”get test.txtlcd “C:\filetransfer\put”put test2.txtquit |
Use the following command to authenticate to your host and run the file transfer batch file.
sftp2 B <path>\<batch_file.txt> <username>@<hostname>Note: The B parameter is case sensitive and is capitalized. For more information on this parameter see Technical Note 1909.
sftp2 B C:\MyFiles\hostcopy.txt SReynolds@myhostTo test the transfer, open a command window on the client workstation and issue the command.
If you plan to automate further processes using a Windows batch file, you can include this sftp2 command line in the Windows batch file.