FTP Download
I am running a FTP Task that loops through each file in the directory -- and it downloads = no problem. However, the task fails when there are no files in the specified directory (I get this error: [FTP Task] Error: Unable to connect to FTP server using "FTP Source". ) filter for *.txt. files Any suggestions? note: I have done a test via VB to check if there are any files in the FTP directory, but I'm chasing my antiquated knowledge. If that will work, let me know what works for you guys.Claudia
May 9th, 2011 4:42pm

correction: the error is: [FTP Task] Error: File represented by "/*.txt" does not exist.Claudia
Free Windows Admin Tool Kit Click here and download it now
May 9th, 2011 5:07pm

What do you want to have happen, and what do you mean by a "test via VB to check if there are any files"? Talk to me now on
May 9th, 2011 5:28pm

Hello use this code: string FtpClientPath = Dts.Variables["Client_DownloadPath"].Value.ToString(); string RemotePath = Dts.Variables["FTP_DownloadPath"].Value.ToString(); string ServerNm = Dts.Variables["ServerName"].Value.ToString(); string ServerUserNm = Dts.Variables["ServerUserName"].Value.ToString(); string ServerUserPwd = Dts.Variables["ServerPassword"].Value.ToString(); string ServerPort = Dts.Variables["Port"].Value.ToString(); string TimeOut = Dts.Variables["Timeout"].Value.ToString(); string ChunkSize = Dts.Variables["ChunkSize"].Value.ToString(); string Retries = Dts.Variables["Retries"].Value.ToString(); ConnectionManager cm = Dts.Connections.Add("FTP"); cm.Properties["ServerName"].SetValue(cm, ServerNm); cm.Properties["ServerUserName"].SetValue(cm, ServerUserNm); cm.Properties["ServerPassword"].SetValue(cm, ServerUserPwd); //cm.Properties["ServerPort"].SetValue(cm, ServerPort); cm.Properties["Timeout"].SetValue(cm, TimeOut);// 'The 0 setting will make it not timeout cm.Properties["ChunkSize"].SetValue(cm, ChunkSize);// '1000 kb cm.Properties["Retries"].SetValue(cm, Retries); FtpClientConnection ftp = new FtpClientConnection(cm.AcquireConnection(null)); bool result= ftp.Connect(); if (result) { ftp.SetWorkingDirectory(RemotePath); string[] ftp_remotefolder; string[] ftp_remotefiles; //add name of file in list "lstFiles" ftp.ReceiveFiles(lstFiles.ToArray(), FtpClientPath, true, false); }
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 1:13am

You have no error handling in your code therefore when you try and execute ftp.ReceiveFiles(lstFiles.ToArray(), FtpClientPath, true, false); your code will fail if no files exists. Perhaps try something like this: try { ftp.ReceiveFiles(lstFiles.ToArray(), FtpClientPath, true, false); } catch (Exception ex) { //Do something } Jeff Wharton MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt)
May 10th, 2011 1:33am

Good advice, Jeff. I would add that you also should not be performing a "Dts.Connections.Add" - despite what the comments from MSFT in the script task say. You should instead have created an FTP connection manager in the designer, and use Dts.Connections["FTP"] to retrieve it. Talk to me now on
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 11:46am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics