Recently I was asked by a client to implement some sort of system that will establish a sFTP connection to a remote server and download the desired data. Initially I was like, yeah easy, get a sFTP FOSS client, configure it with the remote servers’ details, schedule it and done!
Well… Wasn’t I in for a surprise!!! Turns out that there isn’t really any nice, simple GUI software which can be scheduled and off we go. Nope, CLI all the way baby! Of course, there is Filezilla which can establish sFTP connections and other FTP software around, including cuteFTP but for that you have to pay, and you know… I like my FOSS, so I didn’t really want to go down that route.
So I finally settled for PSFTP – Putty sFTP client, after reading up its short but comprehensive manual I got it working the way I wanted it to like so:
Download PSFTP from the PuTTY page and extract it in a folder in your C drive or, somewhere where it will be easy to navigate to via CMD
Open Notepad or your favourite text editor and put in the following commands in:
psftp.exe <username>@<remote host> -pw <password> -b script.scr
I think that most commands are self-explanatory apart from the -b script.scr, the -b command simply loads a file which contains commands specifically for PSFTP to perform while connected to the remote host.
Open Notepad or your favourite text editor again and this time we’ll input commands which PSFTP will perform once it has connected to the remote host. In my instance, I wanted to simply download all of the contents of a directory locally into a directory of my choice:
get -r <remote directory> <local directory> quit
If the contents or the directory which you want to download are in a sub-folder then you can simply use the cd command:
cd /path/to/directory get data.file mycustomname.file quit
Once the desired commands have been written in the text file it is time to save it as script.scr and place it in the same directory as psftp.exe.
If everything went according to plan, then it should all output something like this:
1234567 C:\DLDATA>psftp.exe email@example.com -pw sftppassword -b script.scrUsing username "myusername".Remote working directory is /remote:/outgoing/test235 => local:DLFILES\test235remote:/outgoing/test2355 => local:DLFILES\test2355C:\DLDATA>
The above output was from a connection being established, and downloading all of the contents of a from a folder called outgoing which resides in root. Then with the get -r command all of the contents of the outgoing directory get copied locally in the DLFILES directory. Done!
For more comprehensive information the PSFTP page has more commands and examples which can further enhance the utility.