Attachmate Worldwide  |   Contact Us  |   NetIQ.com
Home » Support » Solution Library

Technical Notes

Automating SFTP File Transfers with F-Secure SSH
Technical Note 1934
Last Reviewed 31-May-2006
Applies To
F-Secure SSH Client for Windows version 5.1 through 5.4
Summary

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.

Establish an Authentication Method that can be Automated

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.

Note the following:

  • For detailed steps on configuring a version 5.x F-Secure SSH Client or Server for public key authentication with an empty passphrase, see Technical Note 1915.
  • If you will be connecting to an OpenSSH server, you must also convert the public key from SecSH format to OpenSSH format. For details on making this conversion when using F-Secure SSH version 5.4, see Technical Note 1919.

Create a Batch File of SFTP Commands

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/user
lcd  “C:\filetransfer\get”
get test.txt
lcd “C:\filetransfer\put”
put test2.txt
quit

Use the SFTP2 Command to Authenticate and Run the File

Use the following command to authenticate to your host and run the file transfer batch file.

Syntax

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.

Example

sftp2 –B C:\MyFiles\hostcopy.txt SReynolds@myhost

To 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.

Related Technical Notes
1909 SFTP2.EXE -b and -B Parameters and F-Secure SSH
1915 How to Configure Authentication that Does Not Require User Input in F-Secure SSH Client for Windows
1918 The Relationship Between File Transfer, SSH, SCP2 (scp), and SFTP
1919 Configuring Public Key Authentication for F-Secure SSH Client for Windows and OpenSSH Server

Did this technical note answer your question?

Yes    No    Somewhat     Not sure yet

Additional comments about this tech note:

Need further help? For technical support, please contact Support.