Using Secure Shell FTP (SFTP)

Topics:

Before using SFTP with DataMigrator, you need to set up SSH connections without passwords.

For example, if your DataMigrator Server is a on a Linux system called local and you want to retrieve or write files on a server called remote, you should log on to your local system with your user ID, for example, user. Then, you need to generate a key file:

/home/user/$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
10:7d:25:cb:ff:1d:c5:f4:1e:dc:7d:44:20:fd:21:56 home@local
/home/user/$

This process creates two files in your .ssh directory: your private key id_rsa and your public key id_rsa.pub. Then, you need to add your public key to the authorized users on the remote server. You can do this using FTP.

On most Linux systems you should able use the command ssh-copy-id.

For remote, enter the name of your remote (SFTP) server.

/home/user$ ssh-copy-id user@remote
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
     "/home/user/.ssh/id_rsa.pub"

Note: If the command ssh-copy-id is not available on your system, use the following command instead:

/home/user$ cat ~/.ssh/id_rsa.pub | ssh user@remote
    "cat >> ~/.ssh/authorized_keys"
user@remote's password: password
/home/user$

You can verify if this worked by using SFTP. You should not get prompted for a password.

/home/user/$ sftp user@remote
Connecting to remote...
sftp> quit
/home/user/$  

Your connection is now set up. In the Data Management Console, expand the Adapters folder. Then expand the Configured folder. Right-click Delimited Flat File (or Flat File) and click Add Connection. You can now select SFTP as the transfer protocol.

Using SFTP From Windows

How to:

Starting in 2015 and the Windows 10 release, you can enable and use SSH and SFTP on the Windows platform.

In order to use SFTP with DataMigrator, you need to install OpenSSH and set up secured connections without a password from your Windows machine.

Note: Since you are using a local machine, it should be sufficient to only install a client SSH software.

Before following the procedures below, verify if you have SSH integrated on your Windows machine by opening the Command Prompt window and entering ssh.

If you get a response describing usage syntax, then you have SSH enabled on your Windows machine. Otherwise, please see How to Install the SSH Client on Windows.

To ensure that SFTP is integrated with your Windows machine after SSH is enabled, open the Command Prompt window and enter sftp.

Procedure: How to Install the SSH Client on Windows

To install the SSH client:

  1. On your Windows machine, click the Windows Start menu.
  2. Click Settings to open the Settings window.
  3. Click Apps and then click Apps & features.
  4. Click Manage optional features and then click Add a feature.
  5. Scroll through the list of features and click Open SSH Client to expand the window, and then click Install.
  6. After the installation is complete, open the System Properties for the machine and click Environment Variables.

    The Environment Variables dialog box opens.

  7. In the System Variables section, verify that %SYSTEMROOT%\System32\OpenSSH\ was added to the Path.

    Note: You might need to reboot your machine to complete the installation process.

Procedure: How to Establish a Secure Password-less SFTP Connection

You can establish a SFTP connection that does not require a password by following these steps:

  1. On your remote machine ensure that you have the .ssh sub-directory located in the /home/user directory, and an authorized_keys file that will store a public key from your local machine. If the directory and the file do not exist, you need to create them. The following example syntax shows how you can create these files:
    /home/user/$ mkdir .ssh
    /home/user/$ touch .ssh/authorized_keys
    
  2. On your local Windows machine ensure that you have the .ssh sub-directory in the /home/user directory, for example, C:\Users\userid\.ssh. To create private and public keys (id_rsa and id_rsa.pub), enter the following command:
    /home/user/$ ssh-keygen -t rsa
    

    You can use all of the default values by pressing the Enter key at the prompts, or enter your preferred values.

  3. Connect to your remote machine and append your public key (content of id_rsa.pub) to the authorized_keys file on the remote machine:
    /home/user/$ ftp remuser@remotemachine
    ftp> lcd .ssh
    ftp> cd .ssh
    ftp> append id_rsa.pub authorized_keys
      [ or /home/user/$ cat ~/.ssh/id_rsa.pub | (ssh remuser@remotemachine "cat >> ~/.ssh/authorized_keys")  ]
    ftp> quit
    /home/user/$ sftp remuser@remotemachine
    

    The last command line may ask you if you want to save the keys permanently. Enter yes when prompted.

  4. Verify the SFTP connection. You should not get prompted for a password.
    /home/user/$ sftp remuser@remotemachine
    Connecting to remote...
    sftp> quit
    

Using SFTP From Early Windows Versions

While Windows does not include an SFTP client program, there are programs available from both open source and commercial sources that implement the protocol.

One free source is PuTTY, which supplies a collection of utilities including a client program (psftp.exe) with similar functionality. They also provide puttygen.exe for generating private or public key pairs and converting an existing private key to a file in their .ppk format.

To use PuTTY's PSFTP:

  1. Go to the PuTTY Download Page, download the MSI installer, and run it to install and configure their utilities. Alternatively, download psftp.exe and puttygen.exe to a directory in your PATH.
  2. Download a private key to your Windows system or generate a new key using puttygen. Save it to a directory of your choice, for example, C:\putty\id_rsa.ppk.
  3. If necessary, add your public key to ~/.ssh/authorized_keys on the remote server.
  4. Test the connection from the command line using the following lines:
    drive:\> psftp -v -i "drive:\putty\id_rsa.ppk" user@remote 
    Using username "user"
    The server's host key is not cached in the registry
    ...
    Store key in cache? (y/n) y
    Remote working directory is /home/user
    psftp> ls
    psftp> quit
    

    where:

    drive
    Is the drive on which the private key is saved.
    user

    Is your user ID.

    remote

    Is the name of your remote server.

    You should not be prompted for a password or passphrase. However, if you have not previously connected to the server, you will be prompted to store the key in the cache. Reply y and you will not be prompted again. You must do this so that the DataMigrator Server does not receive this prompt.

  5. In your PATH, create a file called sftp.bat with the following lines:
    @echo off
    psftp -i "drive:\putty\id_rsa.ppk" %1 %4 %5 %6 –batch

    where:

    drive
    Is the drive on which the private key is saved.

If your DataMigrator Server is running, shut it down and then start it again. You can now configure a connection for a (delimited) flat file for a remote connection using SFTP.

WebFOCUS

Feedback