當我運行一個調用上述SSIS包的作業時,我需要知道給定的FTP服務器上是否存在特定的文件。目前我使用的是涵括以下代碼腳本任務(SSIS中):通過SSIS檢查FTP服務器上是否存在文件的最佳方法?
string userName = Dts.Variables["User::ftp_username"].Value.ToString();
string password = Dts.Variables["User::ftp_password"].Value.ToString();
string fileName = Dts.Variables["User::download_file_name"].Value.ToString();
string ftpURL = String.Format("ftp://abc.def.com/{0}", fileName);
try
{
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(ftpURL);
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpRequest.Credentials = new NetworkCredential(userName, password);
using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())
{
Dts.Variables["User::fileExists"].Value = true;
}
}
catch
{
Dts.Variables["User::fileExists"].Value = false;
}
Dts.TaskResult = (int)ScriptResults.Success;
然而,這是調用WebRequestMethods.Ftp.DownloadFile
方法,它根據MSDN網站是用來被用於從下載文件一個FTP服務器。 I just need to know if the file exists, not download it
。
此外,有沒有更好的方法來檢查文件的存在?
PS。我是C#的新手,所以我很抱歉,如果天真!