简体   繁体   中英

Check 3 files exists in different folder on ftp server

I have 3 variable that contains the path of the file, each file is in different folder but the same ftp server:

The first variable called file1 contain that value /ds/product/Jan/09122016_product.csv

The second variable called file2 contain that value /ds/subproduct/Jan/09122016_subproduct.csv

The third variable called file3 contain that value /ds/category/Jan/09122016_category.csv

What i want is to check if the 3 files exists in the ftp in one code.

Actually i can verify only one file in one script task in my case if i want to check the 3 files i need 3 script task but i want to optimize this how can i do that ?

string[] folderArray, fileArray;
ConnectionManager cm = Dts.Connections["FTP"];
FtpClientConnection ftpClient = new  FtpClientConnection(cm.AcquireConnection(null));
ftpClient.Connect();
ftpClient.SetWorkingDirectory("/ds/product/Jan/");
ftpClient.GetListing(out folderArray, out fileArray);

foreach (String file in fileArray)
{
    if (file.Equals("09122016_product.csv"))
    {

    }
}

I'd check the timestamp of the files you're polling using FTP MDTM, but this isn't supported by FtpClientConnection.

Is using System.Net.FtpWebRequest an option? This class supports MDTM with the WebRequestMethods.Ftp.GetDateTimestamp method. It's a bit unclear to me how the FTP control connection lifecycle is handled by this class (it's kept open by default), so I'd test that before deploying to production if the script is heavily used.

See this SO question for a code example: System.Net.FtpWebRequest GetDateTimestamp example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM