Schedule a Task to pull files from sFTP Server

Files from sFTP server can be downloaded to the local system easily using the free tool such as winscp.

1. Download WinSCP From here

WinSCP :: Download

2. Install WinScp to the client machine

3. Copy the below script and paste in a text file called “sFTP_Script.txt” and place it in C:\sFTPPull folder you wish

# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
# open sftp://user:password@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Connect
open sftp://sFTPTest:Fh2EsZwi@sFTPServer.MyCompany.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
# Change remote directory
cd /
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
get *.txt c:\
# Disconnect
close

4. Either you can download file using command line or by scheduling a task in Windows Task Scheduler.

5. Command line is :-

C:\ProgramFiles\WinSCP\WinSCP.exe /console  /script="C:\sFTPPull \sFTP_ Script.txt"

6. The File would be written to C:\ drive, but it can be changed to the destination folder you wish by editing the “get *.txt C:\ “ line.

Articles Referred :-

http://winscp.net/eng/docs/scripting#hostkey

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s