SFTPfd

30.10.2018, updated November 2022

command line, sftp, silent, unattended, utility, as it is

Why? Task was to have a command-line utility for getting files from remote site and remove them from there, unattended.

Prereqs: Windows, PowerShell 5.1+.

This program (command-line utility) copies files and directories using SFTP from remote location to local directory and removes these from source when needed (as default). No GUI, parameters (options) need to be set in configuration file.

Utilized Posh-SSH by Carlos Perez, NuGet package provider is also installed as prerequisite. Thanks!

NuGet package provider and Posh-SSH (essential) module need elevated rights to be installed, if to prefer system setup of module.
For Posh-SSH local install (into same directory where program is running from) no admin rights needed. Parameter LocalInst need to be added into configuration file. See below.
Mandatory is in configuration file (located in program running directory and named as SFTPfd.cfg) to set remote host (by default is used port 22), remote directory and local directory, both must exist. If user name and/or password is missing, credentials dialog appear. Password (if accordingly set in configuration file*, see options below) is possible to save (in file in program running directory and named as SFTPfd.pwd) for later unattended use. Saved password is kept secure and possible to use only on current computer. To reset saved password just remove file SFTPfd.pwd.

* Keep in mind that password is kept as plain text in configuration file!

Configuration file example:

10.162.7.15:91
/Some/Thing
C:\temp\DL
UN=Alfa

LocalInstLatest

Options:

PW=<save> – password is secure-saved for later use unattended
Force – overwrite files with same length and time found in target directory
LocalInst – module Posh-SSH is installed into program directory, for PowerShell 5.1 i
s installed module version 2.3*, for other latest
LocalInstLatest – latest Posh-SSH module is installed, but when module already installed it is not renewed for keeping version of choice, in this case for latest to install just remove directory
LocalInstLatestCheck – latest Posh-SSH module is installed, always checked for latest
NoRemove – no files/directories removed from source directory
NoScreen – by default red box in left upper corner show activity, with this parameter no activity is shown

* I've seen some errors using latest Posh-SSH module with PS 5.1, but ... perhaps it depends. So, using latest version is recommended, at least as point to start, see err-logs if any.

Activity and error logs is created in directory program is started from. Main log-file is named as "SFTPfd.<computer name>.log". In file "SFTPDfd.err" is noted current session error(s).

12.11.2022 [LocalInst[Latest[Check]]]

11.11.2022 file 'SFTPfd is running.temp' is kept in running directory during program run; credentials ask/save

09.11.2022 Posh-SSH local install ([LocalInst]), PowerShell 7.x adaptation

08.11.2022 file copy check, no screen option, force option

...

08.03.2018 initial version