Want to use C# (FtpWebResponse) to read file list from FTP, but it returns HTML

后端 未结 4 616
既然无缘
既然无缘 2020-12-11 08:54

I use below codes to get files from a FTP site. It works in my computer, but it only return HTML codes when I run it on another computer (I can see that the HTML are codes o

相关标签:
4条回答
  • 2020-12-11 09:08

    FTP Requires PassiveMode to download, upload...

    Instead, try to use:

    reqFTP.UsePassive = true;
    
    0 讨论(0)
  • 2020-12-11 09:17

    This is the result of using FtpWebRequest through an HTTP Proxy. The file listing gets pretty printed with HTML tags which have <A> hyperlinks to the individual files in the listing.

    If you can't bypass the proxy, in our case it was possible to scrape the section with the file contents out of an enclosing <PRE> element, load it into an XmlDocument, and pull the file list out through .SelectNodes("//A/text()")

    0 讨论(0)
  • 2020-12-11 09:18

    I found the solution: the default proxy was enabled unexpectedly

    I now have to disable it specifically using a config file:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
       <system.net>
        <defaultProxy enabled="false" useDefaultCredentials="true"/>
      </system.net>
    </configuration>
    

    In fact, it is really a .NET issue!

    0 讨论(0)
  • 2020-12-11 09:26

    Could it be a web proxy interfering? Try to get around the proxy by using the following:

    reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
    
    0 讨论(0)
提交回复
热议问题