Search code examples
vb.netinternet-explorerftpwindows-explorer

FTP Directory browsable in Internet Explorer but not in Windows Explorer; VB.NET code to fake web browsing


I have a strange case where a client's FTP server is fully browsable in a web browser, but not in a file explorer.

This is what I see in IE: ftp in IE

And this is what I see in Windows Explorer: ftp in Windows

What I'm really trying is to write code that reads the list of files from this ftp directory:

Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create(ftpServer), FtpWebRequest)
ftpRequest.Credentials = New NetworkCredential(ftpServerUsername, ftpServerPassword)
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails

Dim ftpResponse As FtpWebResponse = CType(ftpRequest.GetResponse(), FtpWebResponse)
Dim ftpResponseStream As Stream = ftpResponse.GetResponseStream()
Dim ftpResponseStreamReader As StreamReader = New StreamReader(ftpResponseStream)

Console.WriteLine(ftpResponseStreamReader.ReadToEnd())

ftpResponseStreamReader.Close()
ftpResponseStream.Close()
ftpResponse.Close()

But the code fails with a 451 error:

The remote server returned an error: (451) Local error in processing.
(Details: 451 requested action aborted: local error in processing)


Questions:

  1. Why is the FTP browsable on IE but now in Windows? Should I tell my client to change some properties on the FTP setup to make it directory-browsable in Windows?

  2. Is (1) necessary? Instead is it possible to add/change my code to imitate web-browsing so that the list of files can be read?


Solution

  • Ciarán's comment helped access files via Windows Explorer: the URL of the format ftp://username:password@IPAddress/ worked.


    For the code, however, a slash "/" at the end of the URL did the trick!

    I changed the directory name from ftp://server/directory to ftp://server/directory/ and BOOM! VB was able to retrieve the list of files!

    I tried the same in IE, and here's what I get:

    ftp://193.XX.XX.XX/flog: ftp browsing without slash after directory name

    ftp://193.XX.XX.XX/flog/: (note the "/" at the end of directory name) ftp browsing with slash after directory name

    Anyone else stumbling here with a (451) Local error in processing can try this and see if it helps!

    Additional Note: The URL of the format ftp://username:password@IPAddress/ (again, note the ending "/") also works in code. With this, you can skip the line ftpRequest.Credentials = ....