1. access https://winscp.net
![](https://t1.daumcdn.net/cfile/tistory/232DF34B5824AA960E)
2. Click! [Installation package]
![](https://t1.daumcdn.net/cfile/tistory/2507134B5824AA9934)
3. You can download setup file
![](https://t1.daumcdn.net/cfile/tistory/247FF14B5824AA9C38)
4. Install
![](https://t1.daumcdn.net/cfile/tistory/222A3D4B5824AA9E12)
5. Proceed with the installation
![](https://t1.daumcdn.net/cfile/tistory/2429214B5824AAA013)
--------------------------------------------------------------------------------------------------------------------------
.Net assembly
1. You can look "WinSCPnet.dll" after you install WinSCP above.
![](https://t1.daumcdn.net/cfile/tistory/211E543E5824CE3731)
2. Run the following code
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /i WinSCPnet.dll
![](https://t1.daumcdn.net/cfile/tistory/241E383E5824CE3930)
--------------------------------------------------------------------------------------------------------------------------
Development SSIS
1. You can look "WinSCPnet.dll" after you install WinSCP above.
![](https://t1.daumcdn.net/cfile/tistory/211461445824D09A26)
2. Click "Variables" on new small window after mouse right click at anywhere
![](https://t1.daumcdn.net/cfile/tistory/211F033B5824D31E28)
3. Make Variables value by your SFTP information
![](https://t1.daumcdn.net/cfile/tistory/261FB33B5824D32028)
4. Click small icon after double click [Script Task Editor]
And, Select Variables that you made previous
![](https://t1.daumcdn.net/cfile/tistory/251FA73B5824D32229)
5. Click [Edit Script]
![](https://t1.daumcdn.net/cfile/tistory/221E993B5824D3252A)
6. Add WinSCPnet.dll into "Reference" (The dll file location = C:\Program Files (x86)\WinSCP )
![](https://t1.daumcdn.net/cfile/tistory/241FFB3B5824D32728)
7. Add below code into Main() method.
// TODO: Add your code here
string winscpPath = Dts.Variables["winSCPPath"].Value.ToString();
string username = Dts.Variables["User::UserName"].Value.ToString();
string password = Dts.Variables["User::Password"].Value.ToString();
string hostName = Dts.Variables["User::HostName"].Value.ToString();
string localPath = Dts.Variables["User::LocalPath"].Value.ToString();
string remoteFTPDirectory = Dts.Variables["User::FTPDirectory"].Value.ToString();
string sshKey = Dts.Variables["SshHostKeyFingerprint"].Value.ToString();
Boolean winSCPLog = (Boolean)Dts.Variables["User::winSCPLog"].Value;
string winSCPLogPath = Dts.Variables["User::winSCPLogPath"].Value.ToString();
SessionOptions sessionOptions = new SessionOptions
{
Protocol =
Protocol.Sftp,
FtpMode = WinSCP.
FtpMode.Active,
FtpSecure =
FtpSecure.None,
HostName = hostName,
UserName = username,
Password = password,
SshHostKeyFingerprint = sshKey,
TimeoutInMilliseconds = 90000
};
try
{
using (Session session = new Session())
{
// WinSCP .NET assembly must be in GAC to be used with SSIS,
// set path to WinSCP.exe explicitly, if using non-default path.
session.ExecutablePath = winscpPath;
session.DisableVersionCheck =
true;
if (winSCPLog)
{
session.SessionLogPath = @winSCPLogPath +
@"WinscpSessionLog.txt";
session.DebugLogPath = @winSCPLogPath +
@"WinscpDebugLog.txt";
}
// Connect
sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey =
true;
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode =
TransferMode.Binary;
try
{
session.GetFiles(remoteFTPDirectory, localPath,
false, transferOptions);
}
catch (Exception e)
{
Dts.Events.FireError(0,
null,
string.Format("Error when using WinSCP to download file: {0}", e), null, 0);
Dts.TaskResult = (
int)DTSExecResult.Failure;
}
}
Dts.TaskResult = (
int)ScriptResults.Success;
}
catch (Exception ex)
{
Dts.Events.FireError(0,
null,
string.Format("Error when using WinSCP to download file: {0}", ex), null, 0);
Dts.TaskResult = (
int)DTSExecResult.Failure;
}
![](https://t1.daumcdn.net/cfile/tistory/2220073B5824D32929)