• <bdo id='5olAc'></bdo><ul id='5olAc'></ul>
      <tfoot id='5olAc'></tfoot>
    1. <legend id='5olAc'><style id='5olAc'><dir id='5olAc'><q id='5olAc'></q></dir></style></legend>
    2. <small id='5olAc'></small><noframes id='5olAc'>

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

    4. 为什么 FtpWebRequest 为这个现有目录返回一个空流

      时间:2023-06-04

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

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

                  <tbody id='DJ4II'></tbody>

                本文介绍了为什么 FtpWebRequest 为这个现有目录返回一个空流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                I'm not sure why am I getting this result. I'm running this on a Linux server. (It's my small web site's shared web hosting account.)

                The files are grouped as follows:

                and the Another Dir has one file inside:

                So I'm trying to retrieve the contents of the badname directory inside 1somelongdir1234567 directory that doesn't exist on the server, using this code:

                try
                {
                    FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(
                        "ftp://server12.some-domain.com/public_html/1somelongdir1234567/badname");
                    ftpRequest.EnableSsl = true;
                    ftpRequest.Credentials = new NetworkCredential("user", "password");
                    ftpRequest.KeepAlive = true;
                    ftpRequest.Timeout = -1;
                
                    ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                
                    using (FtpWebResponse response1 = (FtpWebResponse)ftpRequest.GetResponse())
                    {
                        //*****BEGIN OF EDIT*****
                        Console.WriteLine(response1.StatusDescription);
                        Console.WriteLine(response1.StatusCode);
                        //*****END OF EDIT*****
                
                        using (StreamReader streamReader = new StreamReader(response1.GetResponseStream()))
                        {
                            List<string> arrList = new List<string>();
                
                            for (; ; )
                            {
                                string line = streamReader.ReadLine();
                
                                //I get to here, where `line` is null????
                
                                if (string.IsNullOrEmpty(line))
                                    break;
                
                                arrList.Add(line);
                
                                //*****BEGIN OF EDIT*****
                                Console.WriteLine(line);
                                //*****END OF EDIT*****
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                

                So as you see, there's no such folder badname but instead of throwing an exception, my ftpRequest.GetResponse() succeeds and then streamReader.ReadLine() returns null like I showed in the code above.

                More strangely, if I provide an actual directory as such:

                    FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(
                        "ftp://server12.some-domain.com/public_html/1somelongdir1234567/Another%20Dir");
                

                the streamReader.ReadLine() still returns null.

                Can someone explain why?


                Edit: OK, guys, I updated the code above to retrieve the status code. I'm still puzzled though.

                First, here's three values of connection URI and the response/output that I'm getting:

                Example 1:

                //Existing folder
                "ftp://server12.some-domain.com/public_html/1somelongdir1234567"
                

                Output:

                150 Accepted data connection
                
                OpeningData
                drwxr-xr-x    3 username   username         4096 Sep  5 05:51 .
                drwxr-x---  118 username   99               4096 Sep  5 05:54 ..
                drwxr-xr-x    2 username   username         4096 Sep  5 05:52 Another Dir
                -rw-r--r--    1 username   username           11 Sep  5 05:51 test123.txt
                

                Example 2:

                //Another existing folder
                "ftp://server12.some-domain.com/public_html/1somelongdir1234567/Another%20Dir"
                

                Output:

                150 Accepted data connection
                
                OpeningData
                

                Example 3:

                //Nonexistent folder
                "ftp://server12.some-domain.com/public_html/1somelongdir1234567/SomeBogusName"
                

                Output:

                150 Accepted data connection
                
                OpeningData
                

                So why is it giving me the same result for example 2 as I'm getting for 3?

                As for what ftp server it is, I wasn't able to see it in the network logs nor in FtpWebRequest itself. Here's what I was able to get from Microsoft Network Monitor:

                Welcome to Pure-FTPd [privsep] [TLS] ----------..
                220-You are user number 4 of 50 allowed... 220-Local time is now 13:14. Server port: 21...
                220-This is a private system - No anonymous login..
                220-IPv6 connections are also welcome on this server...
                220 You will be disconnected after 15 minutes of inactivity...

                解决方案

                The URL for the ListDirectory/ListDirectoryDetails method should end with a slash, in general.

                Without a slash, results tend to be uncertain.

                WebRequest.Create("ftp://example.com/public_html/1somelongdir1234567/Another%20Dir/");
                

                这篇关于为什么 FtpWebRequest 为这个现有目录返回一个空流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在任何未处理的异常的情况下退出应用程序 下一篇:FtpWebRequest 返回“550 文件不可用(例如,文件未找

                相关文章

                最新文章

              1. <tfoot id='t0Hby'></tfoot>
                <legend id='t0Hby'><style id='t0Hby'><dir id='t0Hby'><q id='t0Hby'></q></dir></style></legend>

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

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