Automate downloading files from SFTP
psftp your a true treasure
I’ve been struggling lately to find online the right script to help get started with a task I needed to deliver: download a file from a SFTP server in a timely manner (using Windows Task Scheduler). All my searches led me either to FTP download automation scripts (not what I was looking for) or deployments that seemed at that point far to complex.
So… psftp was the chosen tool.
- Look for psftp.exe in puttygen’s website.
- Once downloaded, copy the file to:
3. In your working directory, say C:\DownloadFTPFiles, create a commands.txt file.
This file will contain the browsing command to the relevent directory inside the FTP server using basic DOS commands, i.e. cd folder1 to browse to folder1 and a get command to download the relevant files to your working directory (-r = recursively):
get -r c:\DownloadFTPFiles\FromFTP
4. The syntax is quite simple including the SFTP server, username, password and the path to the commands.txt file.
psftp 188.8.131.52 -l user1 -pw MyPassword123! -b "C:\DownloadFTPFiles\commands.txt"
5. Give it a try, once confirmed the files downloaded successfully you can embed the syntax above in a batch or PowerShell file and add it to a Scheduled Task.