FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

Connection timed out

Open taoyouh opened this issue 9 years ago • 10 comments

ftp://202.120.39.248 works with FileZilla, Windows Explorer, and ftp command on Windows. But it doesn't work with FluentFTP (on both .Net Core 1.1 and UWP) Error Message:

{System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。(Did not response after some time. Connection failed.) 202.120.39.248:63390 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.Sockets.SocketTaskExtensions.<>c.b__3_1(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)}

StackTrace:

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at FluentFTP.FtpSocketStream.Connect(String host, Int32 port, FtpIpVersion ipVersions) at FluentFTP.FtpClient.OpenPassiveDataStream(FtpDataConnectionType type, String command, Int64 restart) at FluentFTP.FtpClient.OpenDataStream(String command, Int64 restart) at FluentFTP.FtpClient.GetListing(String path, FtpListOption options) at FluentFTP.FtpClient.GetListing() at ConsoleApp2.Program.Main(String[] args) in C:\Users\Zhaoquan\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2\Program.cs:line 29

Code:

            FluentFTP.FtpClient conn = new FluentFTP.FtpClient();
            FluentFTP.FtpTrace.LogToConsole = true;
            conn.Host = "202.120.39.248";

            conn.Connect();

            var result = conn.GetListing();

taoyouh avatar Sep 14 '17 08:09 taoyouh

I've had some issues with a couple servers that I was connecting.. I believe those servers are at fault, but for all I know it could be an issue with FluentFTP.

The issue in my case was that FluentFTP will by default attempt to establish a EPSV connection, and will fall back to regular PASV if the server doesn't support it. The server in question reported that it supported EPSV, but connections to it timed out. Forcing a PASV connection solved it for us

client.DataConnectionType = FtpDataConnectionType.PASV;

artiomchi avatar Sep 16 '17 19:09 artiomchi

If you are getting timeouts then try increasing all the timeout limits. This is needed for Azure too.

Thank you @artiomchi for filling in for me!

robinrodricks avatar Sep 21 '17 17:09 robinrodricks

And which is your server and OS?

robinrodricks avatar Sep 21 '17 18:09 robinrodricks

What @artiomchi said works. And it is not timout problem, because it takes 1 second for FileZilla to connect, but takes more than 30 seconds for my code to throw an ExtendedSocketException. I tried both .NET Core 1.1 and UWP on Windows 10.0.15063.

taoyouh avatar Sep 22 '17 00:09 taoyouh

Fail version logging:

# Connect() Status: Connecting to 202.120.39.248:21 Response: 220 Please visit http://sourceforge.net/projects/filezilla/ Response: 220-FileZilla Server version 0.9.41 beta Response: 220-written by Tim Kosse ([email protected]) Command: USER anonymous Response: 331 Password required for anonymous Command: PASS *** Response: 230 Logged on Command: FEAT Response: 211 End Response: 211-Features: Response: MDTM Response: REST STREAM Response: SIZE Response: MLST type*;size*;modify*; Response: MLSD Response: UTF8 Response: CLNT Response: MFMT Status: Text encoding: System.Text.DBCSCodePageEncoding Command: SYST Response: 215 UNIX emulated by FileZilla Status: Auto-detected UNIX listing parser

# GetListing(null, Auto)

# GetWorkingDirectory() Command: PWD Response: 257 "/" is current directory. Command: TYPE I Response: 200 Type set to I

# OpenPassiveDataStream(AutoPassive, "MLSD /", 0) Command: EPSV Response: 229 Entering Extended Passive Mode (|||57119|) Status: Connecting to 202.120.39.248:57119

After Adding client.DataConnectionType = FtpDataConnectionType.PASV;

# Connect() Status: Connecting to 202.120.39.248:21 Response: 220 Please visit http://sourceforge.net/projects/filezilla/ Response: 220-FileZilla Server version 0.9.41 beta Response: 220-written by Tim Kosse ([email protected]) Command: USER anonymous Response: 331 Password required for anonymous Command: PASS *** Response: 230 Logged on Command: FEAT Response: 211 End Response: 211-Features: Response: MDTM Response: REST STREAM Response: SIZE Response: MLST type*;size*;modify*; Response: MLSD Response: UTF8 Response: CLNT Response: MFMT Status: Text encoding: System.Text.UTF8Encoding Command: OPTS UTF8 ON Response: 200 UTF8 mode enabled Command: SYST Response: 215 UNIX emulated by FileZilla Status: Auto-detected UNIX listing parser

# GetListing(null, Auto)

# GetWorkingDirectory() Command: PWD Response: 257 "/" is current directory. Command: TYPE I Response: 200 Type set to I

# OpenPassiveDataStream(PASV, "MLSD /", 0) Command: PASV Response: 227 Entering Passive Mode (202,120,39,248,86,141) Status: Connecting to 202.120.39.248:22157 Command: MLSD / Response: 150 Connection accepted {Listings} Status: Disposing FtpSocketStream...

taoyouh avatar Sep 22 '17 01:09 taoyouh

Update. The server is actually UTF-8, but it seems irrelevant to this problem. The is not a client-side bug, the problem is that the server don't receive EPSV connection. But maybe we should think of this "auto" behavior?

taoyouh avatar Sep 22 '17 01:09 taoyouh

Can you try with the latest build : https://www.nuget.org/packages/FluentFTP/19.0.0

robinrodricks avatar Sep 27 '17 13:09 robinrodricks

@robinrodricks This version works the same. It works only when I use "client.DataConnectionType = FtpDataConnectionType.PASV". It still times out under default configurations.

taoyouh avatar Sep 29 '17 12:09 taoyouh

@robinrodricks So how does this relate to reducing timeouts in relation to Azure Web Apps? It seems contradictory in some cases and may lead to confusion 😅

https://github.com/robinrodricks/FluentFTP#trouble_azure

dcarr42 avatar Nov 16 '17 01:11 dcarr42

Closing as this seems to be server config related and not a bug in FluentFTP.

robinrodricks avatar May 16 '20 17:05 robinrodricks