FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

Can't connect via Proxy anymore after Updating FluentFTP to >=35.2.0

Open wfrx opened this issue 3 years ago • 7 comments

Computer OS: Windows FluentFTP Version: 32.4.3 / >=35.2.0

We need to update FluentFTP to at least 35.2.0 to be able to use SOCKS Proxies. We are currently using Version 32.4.3, which is working fine, except for missing the above functionality. When upgrading to a Version >=35.2.0, our unit tests that use a Proxy all fail with the following error message:

OneTimeSetUp: FluentFTP.FtpException : Can't connect #FTP-Server# via proxy #Proxy-Server#.
Message : Server: squid/3.5.24; Mime-Version: 1.0; Date: Wed, 02 Mar 2022 10:57:20 GMT; Content-Type: text/html;charset=utf-8; Content-Length: 3463; X-Squid-Error: ERR_CONNECT_FAIL 111; Vary: Accept-Language; Content-Language: en; ; Service Unavailable

The difference in our code is only the version of FluentFTP.

Logs : Log from one Unittest with Proxy:

# Connect()
Status:   Connecting to ***:3128
HTTP/1.1 200 Connection established

Response: 220 Microsoft FTP Service
Status:   Detected FTP server: WindowsServerIIS
Command:  USER ***
Response: 331 Password required
Command:  PASS ***
Response: 230 User logged in.
Command:  FEAT
Response: 211-Extended features supported:
Response: LANG EN*
Response: UTF8
Response: AUTH TLS;TLS-C;SSL;TLS-P;
Response: PBSZ
Response: PROT C;P;
Response: CCC
Response: HOST
Response: SIZE
Response: MDTM
Response: REST STREAM
Response: 211 END
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
Command:  SYST
Response: 215 Windows_NT
Status:   Listing parser set to: Windows
Command:  PWD
Response: 257 "/" is current directory.

# DirectoryExists("/Unittest/FtpProxy_2022-03-18_104616")
Command:  CWD /Unittest/FtpProxy_2022-03-18_104616
Response: 550 

# CreateDirectory("/Unittest/FtpProxy_2022-03-18_104616", True)

# DirectoryExists("/Unittest")
Command:  PWD
Response: 257 "/" is current directory.
Command:  CWD /Unittest
Response: 250 CWD command successful.
Command:  CWD /
Response: 250 CWD command successful.
Status:   CreateDirectory /Unittest/FtpProxy_2022-03-18_104616
Command:  MKD /Unittest/FtpProxy_2022-03-18_104616
Response: 257 "/Unittest/FtpProxy_2022-03-18_104616" directory created.

# DirectoryExists("/Unittest/Download")
Command:  PWD
Response: 257 "/" is current directory.
Command:  CWD /Unittest/Download
Response: 250 CWD command successful.
Command:  CWD /
Response: 250 CWD command successful.

# DirectoryExists("/Unittest/FtpProxy_2022-03-18_104616/FtpCreateFolder")
Command:  PWD
Response: 257 "/" is current directory.
Command:  CWD /Unittest/FtpProxy_2022-03-18_104616/FtpCreateFolder
Response: 550 

# CreateDirectory("/Unittest/FtpProxy_2022-03-18_104616/FtpCreateFolder", True)

# DirectoryExists("/Unittest/FtpProxy_2022-03-18_104616")
Command:  PWD
Response: 257 "/" is current directory.
Command:  CWD /Unittest/FtpProxy_2022-03-18_104616
Response: 250 CWD command successful.
Command:  CWD /
Response: 250 CWD command successful.
Status:   CreateDirectory /Unittest/FtpProxy_2022-03-18_104616/FtpCreateFolder
Command:  MKD /Unittest/FtpProxy_2022-03-18_104616/FtpCreateFolder
Response: 257 "/Unittest/FtpProxy_2022-03-18_104616/FtpCreateFolder" directory created.

# GetListing("/Unittest/FtpProxy_2022-03-18_104616", Auto)
Command:  TYPE I
Response: 200 Type set to I.

# OpenPassiveDataStream(AutoPassive, "LIST /Unittest/FtpProxy_2022-03-18_104616", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||63033|)
Status:   Connecting to ***:3128
HTTP/1.1 503 Service Unavailable
Server: squid/3.5.24
Mime-Version: 1.0
Date: Fri, 18 Mar 2022 09:46:18 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 3463
X-Squid-Error: ERR_CONNECT_FAIL 111
Vary: Accept-Language
Content-Language: en

Status:   Disposing FtpSocketStream...

wfrx avatar Mar 18 '22 10:03 wfrx

Can you help debug this?

robinrodricks avatar May 06 '22 05:05 robinrodricks

If you tell me what I can do, I should be able to help.

wfrx avatar May 06 '22 08:05 wfrx

Can you download the fluent FTP source code, add the project to your solution, run debug mode, put a breakpoint in/near the method that is failing, and step through it to see where it goes wrong?

Generally failures always have some exception or something at some level, so if you can isolate the fault, pretty sure I can fix it.

robinrodricks avatar May 06 '22 13:05 robinrodricks

I've included the project but can't get to debug it. I'm not sure what's the issue, I've not worked with external projects like this before.

I can't include any of the .pdb Files from the /bin/Debug folder. Maybe because our project is using .NET 4.8 while there are only 4.5 or 5.0 provided? Could that be the underlying issue for the original problem as well?

Not sure if that helps any, but here's the callstack:

FluentFTP.Proxy.FtpClientHttp11Proxy.ProxyHandshake(FluentFTP.FtpSocketStream)
    FluentFTP.Proxy.FtpClientHttp11Proxy.Connect(FluentFTP.FtpSocketStream, string, int, FluentFTP.FtpIpVersion)
    FluentFTP.FtpClient.OpenPassiveDataStream(FluentFTP.FtpDataConnectionType, string, long)
    FluentFTP.FtpClient.OpenDataStream(string, long)
    FluentFTP.FtpClient.GetListingInternal(string, FluentFTP.FtpListOption, bool)
    FluentFTP.FtpClient.GetListing(string, FluentFTP.FtpListOption)

wfrx avatar May 09 '22 06:05 wfrx

I just tried Version 37.0.4, now it doesn't even give me an error message anymore, just a timeout exception later:

# OpenPassiveDataStream(AutoPassive, "LIST /Unittest/FtpProxy_2022-06-29_121839", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||52180|)
Status:   Connecting to ***:3128
Status:   Disposing FtpSocketStream...

# Dispose()
Status:   Disposing FtpClient object...
Command:  QUIT
Status:   Disposing FtpSocketStream...
Warning:  FtpClient.Disconnect(): Exception caught and discarded while closing control connection: System.TimeoutException: Timed out trying to read data from the socket stream!
   bei FluentFTP.FtpSocketStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   bei FluentFTP.FtpSocketStream.ReadLine(Encoding encoding)
   bei FluentFTP.FtpClient.GetReply()
   bei FluentFTP.FtpClient.Execute(String command)
   bei FluentFTP.FtpClient.Disconnect()
Status:   Disposing FtpSocketStream...
Status:   Disposing FtpSocketStream...

wfrx avatar Jun 29 '22 10:06 wfrx

Can you check now?

https://www.nuget.org/packages/FluentFTP/37.1.0

robinrodricks avatar Jul 12 '22 06:07 robinrodricks

Same behavior.

wfrx avatar Jul 12 '22 11:07 wfrx

I am pretty sure that the described problem happened when "connecting to a host with multiple IP addresses" was "fixed" in the handler for EPSV setup of the new data connection, thereby "causing" the failure of the EPSV connection.

The issue #1205 describes the same problem and we are in the process of fixing this. Please read up the issue there.

I woud like to refer you to issue #1205 if you are still interested in the progress on this issue.

FanDjango avatar Feb 21 '23 20:02 FanDjango