我正在使用FtpWebResponse从ftp服务器下载一个文件。我的代码如下所示:
FtpWebRequest request;
try
{
request = (FtpWebRequest)FtpWebRequest.Create(path);
request.UseBinary = true;
request.Credentials = new NetworkCredential(user, passwd);
request.Method = WebRequestMethods.Ftp.DownloadFile;
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
MemoryStream ms = new MemoryStream();
using (Stream rs = (Stream)response.GetResponseStream())
{
rs.CopyTo(ms);
}
}
}
catch (Exception ex)
{
... error handling code here ...
} 它工作得很好-我能够读取内存流并看到文件。我正在进行测试,所以我将另一个文件复制到ftp服务器,删除了旧的文件,并将新文件重命名为相同的名称,然后重新运行我的程序。我仍然看到旧文件--我从ftp服务器中删除的文件--而不是新文件。所以我删除了新文件--现在ftp服务器上没有文件。我重新运行我的程序,它没有错误地运行,并继续从ftp服务器显示原始文件。如果我直接将ftp发送到ftp服务器,我会验证那里没有文件.
发生什么事了呢?连接被缓存了吗?这些症状已经持续了一个多小时.
发布于 2014-03-17 06:40:56
尝试:
request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);https://stackoverflow.com/questions/22447928
复制相似问题