You can use SSIS script task with Winscp to upload file on FTP using Winscp with the help of scheduling job of ssis Package
use the following code in Script task
string winscpPath = Dts.Variables["winSCPPath"].Value.ToString();
string username = Dts.Variables["ftpUsername"].Value.ToString();
string password = Dts.Variables["ftpPassword"].Value.ToString();
string ftpSite = Dts.Variables["ftpSite"].Value.ToString();
string localPath = Dts.Variables["localPath"].Value.ToString();
string remoteFTPDirectory = Dts.Variables["remoteFTPDirectory "].Value.ToString();
string sshKey = Dts.Variables["sshKey"].Value.ToString();
Boolean winSCPLog = (Boolean)Dts.Variables["winSCPLog"].Value;
string winSCPLogPath = Dts.Variables["winSCPLogPath"].Value.ToString();
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = ftpSite,
UserName = username,
Password = password,
SshHostKeyFingerprint = sshKey
};
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
session.Timeout = new TimeSpan(0,2,0); // two minutes
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
try
{
session.GetFiles(remoteFTPDirectory + "/" +
fileToDownload, 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;