Automating Secure FTP (SFTP) Transfers Using the Reflection FTP Client API

  • 7021275
  • 09-Jan-2003
  • 27-Apr-2018

Environment

Reflection FTP Client version 14.0 or higher

Situation

This technical note describes how to use the Reflection FTP Type Libraries, which provide a COM API to automate secure file transfers. Code samples in C# and VBA are provided.

Resolution

Establish an Authentication Method that Can be Automated

To automate file transfers, Attachmate Technical Support recommends first setting up an authentication method that does not require user input, such as Public Key Authentication with an empty passphrase. It is possible to send a password in your program; however, the security risk is greater when plain text passwords are saved in source code.

For detailed steps on configuring Reflection for public key authentication, see https://support.microfocus.com/kb/doc.php?id=7021932

Reflection FTP Type Libraries

Reflection FTP 1.15 Type Library (RFTPCOM15.DLL) is included with Reflection next-generation emulation products—Reflection Desktop 16, Reflection 2014, and Reflection 2011.

Reflection FTP 1.0 Type Library (RFTPCOM.DLL) is included with Reflection FTP Client 14.x, Reflection for Secure IT 7.x, EXTRA! 9.x, and INFOConnect Enterprise Edition 8.x.

To add a reference to Reflection FTP:

In a .NET project in Microsoft Visual Studio 2005 – 2010, go to Project > Add Reference.

Choose the COM tab and scroll to the FTP type library appropriate to your installation.

In Visual Basic for Applications, go to Tools > References.

Note: If you see both Reflection FTP 1.15 and 1.0 Type Libraries, you may have installed two incompatible versions of Micro Focus products. One will need to be uninstalled before you can use the Reflection FTP API.

For documentation on the Reflection FTP Client API methods and properties, see https://docs.attachmate.com/reflection/ftp/com-api/.

.NET Example

This example uses Reflection FTP 1.15 Type Library and works with Reflection Desktop 16, Reflection 2014, and Reflection 2011. A variable is used to create a filter for file extensions. The application will transfer all files in a given directory that match the strFilter variable.

To see the .NET example:

  1. Download SFTP_ConsoleApp.cs.txt from the Attachmate Download Library.
  2. In Visual Studio, create a new C# console application.
  3. Replace all the code in Program.cs with the text of SFTP_ConsoleApp.cs.txt.
  4. Edit the code to put in the hostname and username of your SFTP server.
  5. Edit the following variables to fit your environment:

strHostPath, strLocalPath, strFilter, and strLogFile.

  1. Run or step into the code.

VBA Example

This example uses Reflection FTP 1.0 Type Library and works with Reflection FTP 14.x and Reflection for Secure IT. VBA is used to create a filter for file extensions. The macro will transfer all files in a given directory that match the strFilter variable.

  1. Download SecureFTP.bas, and import it to a VB or VBA editor.
  2. In your VB or VBA editor, add a reference to Reflection FTP 1.0 Type Library
  3. In the editor, click File > Import; then import SecureFTP.bas.

Using Reflection FTP Automation API, you can add features to your programs, such as checking to see if files exist before attempting a transfer, deleting files when you are done, writing error logs, or emailing system administrators when a critical file transfer fails.

Additional Information

For documentation on the Reflection FTP Client COM API methods and properties, see https://docs.attachmate.com/reflection/ftp/com-api/.

For a list of products that include Reflection FTP Client, see KB 7021276.

Note: For information about automating SFTP file transfers using Reflection for Secure IT command line utilities, see KB 7021998.

SFTP transfers can also be automated using a recorded script instead of using the COM API. For more information on FTP Client scripts, see KB 7021274.

Legacy KB ID

This document was originally published as Attachmate Technical Note 1101.