当我运行一个调用上述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#的新手,所以我很抱歉,如果天真!