WinSCP is powerfull FTP client that easy to automate without need to understand logic behind the FTP except to download the files that needed.
To make it even easier, lets use the WinSCP GUI to generate the skeleton for us
Create a new login, then saved it.
Then click login, we need to login first so we can get the HostKey from the FTP Server.
Click the login information on left, then click Manage
-> Generate Session/URL
then Click Scripts
-> Scripts File
. The scripts will looks like these snippet
open sftp://jack@192.168.1.1/ -hostkey="ssh-ed25519 255 r1n8its3pyJR1NSpKxK08MYNaS5ECp4wxckiHyqdC4A" # Your command 1 # Your command 2 exit # Execute the script using a command like: # "C:\Program Files (x86)\WinSCP\WinSCP.exe" /log="C:\writable\path\to\log\WinSCP.log" /ini=nul /script="C:\path\to\script\script.txt"
For our use case let’s we want to download the whole folder from FTP Server (Linux) folder /data/payments
into D:\Data\
(Windows). Let’s modify the code from WinSCP above, and add the password as well.
then Click Scripts
-> Scripts File
. The scripts will looks like these snippet
open sftp://jack:jackPASSWORD@192.168.1.1/ -hostkey="ssh-ed25519 255 r1n8its3pyJR1NSpKxK08MYNaS5ECp4wxckiHyqdC4A" # download the whole files/folder get /data/payments/ D:\Data\payments\ exit
save it as scpcripts.txt
, the open Command Prompt
, execute the scripts
"C:\Program Files (x86)\WinSCP\WinSCP.exe" /log="D:\Data\WinSCP.log" /ini=nul /script="D:\Code\scpscripts.txt"
use the actual PATH for WinSCP, Log and Script.
After execute the scripts, check the destination folder in Windows
The log files (D:\Data\WinSCP.log
) is very helpfull to debug any issue with the process.
Let say there is an update in FTP Server, just re-run the scripts, it’ll download the file/folder automatically to the Windows.