This is an old revision of the document!
SFTP Task for SSIS
This guide contains description of creating SFTP1 file transfer task for SSIS using WinSCP scripting. Preferred approach is to use WinSCP .NET assembly from SSIS script task .NET code.
WinSCP offers scripting interface that you can use to automate file transfers to/from SFTP server.
Before starting you should:
Advertisement
Script file
Start by creating WinSCP script file to transfer your files.
Below you can see basic script example for downloading file from SFTP server. For details see guide to automation or detailed documentation of scripting functionality.
option batch abort option confirm off open mysession -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" get /remotepath/data.dat c:\localpath\ exit
In the script you need at least to:
- Replace
mysession
argument toopen
command with specification of SFTP connection in formsftp://username:password@hostname
or use name of site (stored session). - Replace host key fingerprint after
hostkey
switch ofopen
command with actual fingerprint of your SFTP/SSH server host key;2 - Replace paths after
get
command with actual paths to remote file to download from and local directory to download to.
Advertisement
Save the script into file accessible from SSIS.
SSIS task
In SSIS, add new Execute Process task to control flow of your package. In the Execute Process Task Editor:
- Put path to WinSCP executable (by default
C:\Program Files\WinSCP\WinSCP.exe
) into Executable; - In Arguments specify
/script=<pathtoyourscript>
; - You may want to set WorkingDirectory to path, where you want to download files to/upload files from, if you do not use absolute paths in your script.
Further Reading
- FAQ about SFTP task hanging when run from SSIS;
- Scripting documentation;
- Command-line parameters;
- Guide to scripting;
- FAQs about scripting;
- Troubleshooting.
Other References
Advertisement