I created a custom FTP server using .NET 4.0. I am running both the client and server on the same Windows 7 machine, and my firewall is entirely disabled. I can connect to it using both FileZilla and FtpUse, establish PASV mode, and browse the contents of folders just fine. The problem comes in when attempting to connect via Windows Explorer. I can log in successfully, but when Explorer sends the PASV command (see client/server exchange below) Explorer pops up a message box that says "FTP Folder Error", "An error occurred opening that folder on the FTP Server. Make sure you have permission to access that folder". The details that follow are the last two responses it received from the server. I found this (http://support.microsoft.com/kb/2754804/en-us) update and installed it, but it didn't help. Anyone have any ideas what this could be? I open the TCP listener before returning a response from the PASV command, so I don't think it's a question of timing.
<< 220 ***********.
>> USER Domain\******
<< 331 Password required.
>> PASS *******
<< 230 Domain\****** logged in.
>> opts utf8 on
<< 200 OPTS UTF8 command successful - UTF8 encoding now on.
>> syst
<< 215 Windows_NT.
>> site help
<< 200
<< 200 End of help.
>> PWD
<< 257 "/".
>> TYPE A
<< 200 Type set to A.
>> PASV
<< 227 Entering Passive Mode (10,0,0,4,7,100)
Originally, I thought the problem might be related to
Windows explorer hangs up FTP connection after PASV command
But I tried opening the passive port ahead of time and it didn't help. Instead, the problem is related to the strictness of Windows Explorer. The IP address supplied as part of the 227 response must be identical to the address of the FTP site the client initially connected. In other words, if the client connects using
ftp://localhost
(which resolves to 127.0.0.1), the IP address provided with the PASV response MUST be 127.0.0.1 - otherwise, Windows Explorer will error. This is not to say that the passive port can't be opened with IPAddress.Any - it can:
var listener = new TcpListener(IPAddress.Any, 0)
However, the address returned with the result must still be 127.0.0.1 (using the above as an example). If the client initially connects with the IP of the machine, say 10.x.x.x for example, the IP address returned with the 227 response must also be 10.x.x.x.
FileZilla must somehow be more forgiving.