Skip to content
David Garratt edited this page Jun 17, 2024 · 4 revisions

In summary sftpGet is a utility which is designed to run as a service and it's purpose is to monitor a folder on a remote SFTP server for a file or files matching a mask and if found download them to the local machine. The remote file is then removed.

See the partner program called sftpSend

Installation

Download the installer for your operating system from Releases. Note that the installer for Windows and MacOS contains a private bundled Jave runtime. However the Linux version requires you to have a Java 17 runtime installed on your distro.

I recommend that you don't install into Program Files folder on windows as this will encounter problems with read-only folder permissions.

Once installed you need to configure the application using the two xml config files shown below.

The program can be run from the command line in a terminal window, or configured as a service for unattended operation.

If you want to setup the program to run as a service you need to open a command prompt with Admininstrator permissions, change into the folder where you installed the application and then run the command line as shown below.

sftpGet_Service /install sftp_Get

You will then need to open up the services control panel within windows and change the account which the program uses to run. By default it will be "System" but you will probably need to create a windows account which has permissions to access the folder that you want to monitor for files.

Configuration

Folder Structure

SFTP Get
├── Images
│   └── icons
│       └── SFTP_Get_Icons
│           └── MyIcon.iconset
├── get
│   └── demo
├── lib
│   ├── app
│   ├── license
│   └── mail
├── logs
├── ssh
└── xml
    └── config


config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    
    <sftpGet2>
        
        <general>
            <value id="title" encrypted="no">SFTP Get from SFTP Server</value>
            <value id="emailEnabled" encrypted="no">false</value>
        </general>
        
        <security>
            <value id="remoteHost" encrypted="no">192.168.1.51</value>
            <value id="remotePort" encrypted="no">22</value>
            <value id="checkKnownHosts" encrypted="no">no</value>
            <value id="knownHostsFile" encrypted="no">./ssh/known_hosts</value>
            <value id="authType" encrypted="no">user password</value>
            <value id="username" encrypted="no">testuser</value>
            <value id="password" encrypted="no">testpassword</value>
            <value id="privateKeyFile" encrypted="no">./ssh/sftpSend</value>
            <value id="privateKeyPasswordProtected" encrypted="no">no</value>
            <value id="privateKeyPassword" encrypted="no"/>      
        </security>
        
        <source>
            <value id="remoteDir" encrypted="no">/My Remote Folder/</value>
            <value id="remoteFileMask" encrypted="no">.xml</value>
            <value id="pollFrequencySeconds" encrypted="no">20000</value>
        </source>
        
        <destination>
            <value id="localDir" encrypted="no">./get/</value>
            <value id="localFileMask" encrypted="no">*.xml</value>
            <value id="backupDir" encrypted="no">./get/backup/</value>
            <value id="tempFileExtension" encrypted="no">.tmp</value>
        </destination>

    </sftpGet2>

</config>

email.xml

<?xml version="1.0" encoding="UTF-8"?>
<emailSettings>    
    
    <configuration>
        <property name="mail.smtp.auth" value="true"/>
        <property name="mail.smtp.starttls.enable" value="true"/>
        <property name="mail.smtp.host" value="smtp.live.com"/>
        <property name="mail.smtp.socketFactory.port" value="25"/>
        <property name="mail.smtp.user" value="email@outlook.com"/>
        <property name="mail.smtp.password" value="password"/>
        <property name="mail.smtp.socketFactory.class" value="javax.net.ssl.SSLSocketFactory"/>
        <property name="mail.smtp.auth" value="true"/>
        <property name="mail.smtp.port" value="25"/>
        <property name="mail.smtp.from" value="email@outlook.com"/>
        <property name="mail.debug" value="true"/>
    </configuration>

    <distributionList id="Monitor" enabled="Y" maxFrequencyMins="0">
        <toAddressList>example@email.com</toAddressList>
    </distributionList>

</emailSettings>

Encrypted settings

You can encrypt the settings held in the xml files above using a utility included.

Lets say you want to encrypt the password used for SFTP.

Open a command prompt and type the following

EncryptData

The program will load and prompt you for the string that you want to encrypt.

Password Utility Input data to encrypt :mysensitivepassword

The program will respond

Encrypted password saved to password.txt

You can then edit/view the contents of the password.txt file and amend the settings in the xml as follows

<value id="password" encrypted="no">mysensitivepassword</value>
<value id="password" encrypted="yes">ElxoCavGZP+i11w3+UhVqqggiJDPPAzxd7s+X2ZddxA=</value>

IMPORTANT - you need to amend the encrypted="no" setting and change it to encrypted="yes" so that the application knows.

Clone this wiki locally