Good article. I have in the past used a simalar solution with Winscp, however we recently change some of our poliacys and the SSIS packagewas moved to a server where 3rd party apps where forbiden. To get around this i found out that you could easly use the c# ftp class in a script task to do the same thing & it's more relable, and faster cause the server doesn't have to fire up another application.
//Get Package Varables
String MyFTPSiteName = Dts.Variables["User::FTPHost"].Value.ToString();
String MyFTPLogin = Dts.Variables["User::FTPUser"].Value.ToString();
String MyFTPPassWord = Dts.Variables["User::FTPPassWord"].Value.ToString();
String MyFolder = Dts.Variables["User::Folder"].Value.ToString();
String MyPeriod = Dts.Variables["User::Period"].Value.ToString();
String MyFileName = Dts.Variables["User::File"].Value.ToString();
//Accept TLS/SSL Certificate
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertificatePolicy);
//Upload Data File
{
FtpWebRequest MyRequest = FtpWebRequest.Create(MyFTPSiteName + "/" + MyFileName ) as FtpWebRequest;
MyRequest.EnableSsl = true;
MyRequest.Credentials = new NetworkCredential(MyFTPLogin, MyFTPPassWord);
MyRequest.Method = WebRequestMethods.Ftp.UploadFile;
//Read File into byte array
FileInfo MyFileI = new FileInfo(MyFolder + "\\"+MyFileName );
FileStream MyFStream = new FileStream(MyFolder + "\\" + MyFileName, FileMode.Open, FileAccess.Read);
BinaryReader MyReader = new BinaryReader(MyFStream);
byte[] MyFile = MyReader.ReadBytes(int.Parse(MyFileI.Length.ToString()));
MyReader.Close();
MyFStream.Close();
MyRequest.ContentLength = MyFile.Length;
//Upload File
Stream MyStream = MyRequest.GetRequestStream();
MyStream.Write(MyFile, 0, MyFile.Length);
MyStream.Close();
FtpWebResponse MyResponse = MyRequest.GetResponse() as FtpWebResponse;
MyResponse.Close();
}
public bool AcceptAllCertificatePolicy(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}