我在FTP服务器中每20分钟创建一次,然后在一定时间后删除。我想在创建之后和删除之前下载文件。我喜欢
while (!File.Exists(reqFTP.RequestUri.ToString()))
{
if (DateTime.Now > timeout)
{
}
Thread.Sleep(TimeSpan.FromSeconds(1));
}
但是每次File.Exists返回false都没有运气。这是完整的代码
string uri = "ftp://" + dtr["FTP_SERVER"].ToString() + "/" + remoteftppath;
Uri serverUri = new Uri(uri);
if (serverUri.Scheme != Uri.UriSchemeFtp)
{
return;
}
var timeout = DateTime.Now.Add(TimeSpan.FromMinutes(1));
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + dtr["FTP_SERVER"].ToString() + "/" + remoteftppath));
reqFTP.Credentials = new NetworkCredential(dtr["FTP_USER_ID"].ToString(), dtr["FTP_PASSWORD"].ToString());
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Proxy = null;
reqFTP.UsePassive = false;
while (!File.Exists(reqFTP.RequestUri.ToString()))
{
if (DateTime.Now > timeout)
{
}
Thread.Sleep(TimeSpan.FromSeconds(1));
}
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
responseStream = response.GetResponseStream();
我不知道出了什么问题。它根本没有从循环中出来