Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 加载时关闭流时发生FtpWebResponse错误550(Windows Server 2012)_C#_Ftp_Windows Server 2012 - Fatal编程技术网

C# 加载时关闭流时发生FtpWebResponse错误550(Windows Server 2012)

C# 加载时关闭流时发生FtpWebResponse错误550(Windows Server 2012),c#,ftp,windows-server-2012,C#,Ftp,Windows Server 2012,我已经阅读了很多关于FtpWebResponse的hte 550问题的信息和问题。但我遇到的问题相当具体。第一次尝试下载文件时,我没有任何问题。响应返回一个流,我正在将其保存到一个文件中 但是,当我第二次尝试为同一个文件调用此方法时,我会检查该文件是否已经存在于我的PC上,如果存在,我会尝试关闭流并处理响应。问题是响应和流在close方法上抛出550个错误 在Wireshark中,在消息“数据连接已打开;传输开始(125)”之后,我得到了Windows Server 2012的550个答案。如何

我已经阅读了很多关于FtpWebResponse的hte 550问题的信息和问题。但我遇到的问题相当具体。第一次尝试下载文件时,我没有任何问题。响应返回一个流,我正在将其保存到一个文件中

但是,当我第二次尝试为同一个文件调用此方法时,我会检查该文件是否已经存在于我的PC上,如果存在,我会尝试关闭流并处理响应。问题是响应和流在close方法上抛出550个错误

在Wireshark中,在消息“数据连接已打开;传输开始(125)”之后,我得到了Windows Server 2012的550个答案。如何能够读取一次文件,而不是仅仅关闭流

代码序列如下所示:

var request = GetNewDownloadRequest(uri);
try
{
   response = GetFTP(request);
}
catch (WebException e)
{
   throw;
}
Stream stream = response.GetResponseStream();
if (!File.Exists(localPath))
{
   SaveToFile(stream);
}

stream.Close();
response.Close();
stream = File.OpenRead(localPath);
发送一个请求而不使用它进行下载允许我检查文件是否也存在于FTP服务器上

我还比较了我的应用程序和Chrome中的下载。唯一的区别是Chrome在两者之间使用CWD命令,所以我使用了,但最终它没有帮助


我想的最后一件事是,我从响应中获取一条流,只是为了关闭它。我能在不读取一个字节的情况下关闭一个流吗?我可以解析一个流来关闭它吗?

我当前的解决方案是,您不能从响应中关闭流,也不能在调用响应时同时关闭响应。清理所有内容的唯一方法是将整个流复制到(例如)MemoryStream,然后您可以同时关闭这两个流