• <bdo id='czkqG'></bdo><ul id='czkqG'></ul>

    <legend id='czkqG'><style id='czkqG'><dir id='czkqG'><q id='czkqG'></q></dir></style></legend>

      1. <tfoot id='czkqG'></tfoot>

        <i id='czkqG'><tr id='czkqG'><dt id='czkqG'><q id='czkqG'><span id='czkqG'><b id='czkqG'><form id='czkqG'><ins id='czkqG'></ins><ul id='czkqG'></ul><sub id='czkqG'></sub></form><legend id='czkqG'></legend><bdo id='czkqG'><pre id='czkqG'><center id='czkqG'></center></pre></bdo></b><th id='czkqG'></th></span></q></dt></tr></i><div id='czkqG'><tfoot id='czkqG'></tfoot><dl id='czkqG'><fieldset id='czkqG'></fieldset></dl></div>

        <small id='czkqG'></small><noframes id='czkqG'>

      2. C# - FtpWebRequest - 通过同一连接/登录的多个请求

        时间:2023-06-04
          <tbody id='fxmN1'></tbody>
        <i id='fxmN1'><tr id='fxmN1'><dt id='fxmN1'><q id='fxmN1'><span id='fxmN1'><b id='fxmN1'><form id='fxmN1'><ins id='fxmN1'></ins><ul id='fxmN1'></ul><sub id='fxmN1'></sub></form><legend id='fxmN1'></legend><bdo id='fxmN1'><pre id='fxmN1'><center id='fxmN1'></center></pre></bdo></b><th id='fxmN1'></th></span></q></dt></tr></i><div id='fxmN1'><tfoot id='fxmN1'></tfoot><dl id='fxmN1'><fieldset id='fxmN1'></fieldset></dl></div>

        <small id='fxmN1'></small><noframes id='fxmN1'>

        <legend id='fxmN1'><style id='fxmN1'><dir id='fxmN1'><q id='fxmN1'></q></dir></style></legend>

        1. <tfoot id='fxmN1'></tfoot>

                <bdo id='fxmN1'></bdo><ul id='fxmN1'></ul>
                  本文介绍了C# - FtpWebRequest - 通过同一连接/登录的多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想循环访问 FTP 文件夹以检查文件是否到达

                  I want to loop on a FTP folder for check if a file has arrived

                  我愿意:

                  FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://localhost:8080");
                  request.Credentials = new NetworkCredential("anonymous", "");
                  request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                  
                  while(true)
                  {
                      using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                      using (Stream responseStream = response.GetResponseStream())
                      using (StreamReader reader = new StreamReader(responseStream))
                      {
                          Console.WriteLine(reader.ReadToEnd());
                  
                          reader.Close();
                          response.Close();
                      }
                  }
                  

                  但是在第二次迭代中我得到了一个异常:

                  But at the second iteration I get an exception:

                  无法读取流

                  推荐答案

                  对不起,我错过了,您只发出一个请求并尝试多次获得响应.试试下面的代码:

                  Sorry, I missed it, you're only issuing one request and trying to get a response multiple times. Try the code below:

                  while(true)
                  {
                      FtpWebRequest request =     (FtpWebRequest)WebRequest.Create("ftp://localhost:8080");
                      request.Credentials = new NetworkCredential("anonymous", "");
                      request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                  
                      using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                      using (Stream responseStream = response.GetResponseStream())
                      using (StreamReader reader = new StreamReader(responseStream))
                      {
                          Console.WriteLine(reader.ReadToEnd());
                  
                          reader.Close();
                          response.Close();
                      }
                  }
                  

                  您应该在每个循环结束时添加某种暂停.你不想轰炸服务器.

                  You should add a pause of some sort at the end of each loop though. You don't want to bombard the server.

                  这篇关于C# - FtpWebRequest - 通过同一连接/登录的多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 FtpWebRequest 正确断开与 FTP 服务器的连接 下一篇:FluentFTP - 连接时出现错误“尝试从套接字流读取

                  相关文章

                  最新文章

                • <i id='q1qMs'><tr id='q1qMs'><dt id='q1qMs'><q id='q1qMs'><span id='q1qMs'><b id='q1qMs'><form id='q1qMs'><ins id='q1qMs'></ins><ul id='q1qMs'></ul><sub id='q1qMs'></sub></form><legend id='q1qMs'></legend><bdo id='q1qMs'><pre id='q1qMs'><center id='q1qMs'></center></pre></bdo></b><th id='q1qMs'></th></span></q></dt></tr></i><div id='q1qMs'><tfoot id='q1qMs'></tfoot><dl id='q1qMs'><fieldset id='q1qMs'></fieldset></dl></div>
                  <tfoot id='q1qMs'></tfoot>

                      <small id='q1qMs'></small><noframes id='q1qMs'>

                      • <bdo id='q1qMs'></bdo><ul id='q1qMs'></ul>
                      <legend id='q1qMs'><style id='q1qMs'><dir id='q1qMs'><q id='q1qMs'></q></dir></style></legend>