Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
15.9k views
in .NET FTP by (400 points)
Hi!

I'm using edtFTPnet/Free to connect to an ftp server and download a file. This works perfectly if I use a .net Windows application, but if use it in .net Service application I cannot establish a connection to the server.
The error that appears is:

"Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."

Is there any limitation of this version with service applications? What could be going wrong? :(

Any help you can provide is much appreciated.

15 Answers

0 votes
by (162k points)
First thing to do is to enable logging to a file at the Debug level (see the documentation for how to do that).

Then post the relevant snippet of the log.
0 votes
by (400 points)
Hello again,

Well viewing the log I can see that it connects to the server logs in and that the error occurs when it's getting the file, which in this case is "NIVUSXXX.TXT".

DEBUG [FTPControlSocket] 20 Ago 2010 13:43:10.015 : 200 Port command okay
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:10.016 : ---> RETR NIVUSXXX.TXT
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:10.434 : 150 Opening data connection for RETR (89.123.170.2,2472)
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : Caught exception
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : System.IO.IOException: Failed to accept connection within timeout period (120000)
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.StandardSocket.Accept(Int32 timeout)
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPActiveDataSocket.AcceptConnection()
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPActiveDataSocket.get_DataStream()
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPClient.GetInputStream()
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPClient.GetBinary(String localPath, String remoteFile)
DEBUG [FTPControlSocket] 20 Ago 2010 13:45:12.037 : Setting socket timeout=500
ERROR [FTPControlSocket] 20 Ago 2010 13:45:13.110 : Read failed ('' read so far)
WARN [FTPClient] 20 Ago 2010 13:45:13.110 : ReadReply failed
WARN [FTPClient] 20 Ago 2010 13:45:13.110 : EnterpriseDT.Net.Ftp.ControlChannelIOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
WARN [FTPClient] 20 Ago 2010 13:45:13.110 : at EnterpriseDT.Net.Ftp.FTPControlSocket.ReadLine()
WARN [FTPClient] 20 Ago 2010 13:45:13.110 : at EnterpriseDT.Net.Ftp.FTPControlSocket.ReadReply()
WARN [FTPClient] 20 Ago 2010 13:45:13.110 : at EnterpriseDT.Net.Ftp.FTPClient.ValidateTransfer()
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : Exception in ValidateTransferOnError())
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : EnterpriseDT.Net.Ftp.ControlChannelIOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : at EnterpriseDT.Net.Ftp.FTPClient.ValidateTransfer()
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : at EnterpriseDT.Net.Ftp.FTPClient.ValidateTransferOnError()
DEBUG [FTPControlSocket] 20 Ago 2010 13:45:13.127 : Setting socket timeout=120000
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : SystemException in Get(string,string)
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : System.IO.IOException: Failed to accept connection within timeout period (120000)
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : at EnterpriseDT.Net.Ftp.FTPClient.GetBinary(String localPath, String remoteFile)
ERROR [FTPClient] 20 Ago 2010 13:45:13.127 : at EnterpriseDT.Net.Ftp.FTPClient.Get(String localPath, String remoteFile)


Does this log help in determining why the the same code works in a windows application but not in a service application?

Thanks in advance...
0 votes
by (162k points)
What's happening here is that you are waiting for the server to connect back to you (as you are in active mode), and the server never replies.

This could be because a firewall is blocking the server from connecting back. Or it could be because the IP address you are supplying to the server is not reachable - so check the IP (and perhaps edit it out of your post). There's a property for setting the active IP address if the local one is not reachable.
0 votes
by (400 points)
Hi, but that doens't make many sense, because on the same machine, with the same ip's and having to pass the same firewalls, if I run the same code on a .net Windows application I can get the file, but if i run the code as a service i get the error i mentioned.
That's why I asked if it could be a version limitation.
0 votes
by (162k points)
Perhaps your Windows service user does not have permission to listen on this port range?

If all other things are equal it must be related to the permissions of your service user in some way.
0 votes
by (400 points)
Hello again,

I tryed running the service as Local System, Local Service, Network Service, and as a user with administrator privileges on the machine, and always received the same error message.

I'm running out of ideas how to solve this problem...
0 votes
by (162k points)
So is the IP address correct and reachable?
0 votes
by (400 points)
Yes the IP is reachable, but it's not that IP, it's a dynamic IP accessed through a DynDns host record.

The DNS resolves to the correct IP, the connection occurs, and the login is sucessful, but fails on the file download.

DEBUG [FTPConnection] 20 Ago 2010 13:43:07.653 : Set LocalDirectory='C:\Windows\system32'
DEBUG [FTPClient] 20 Ago 2010 13:43:07.675 : Connecting to ...:21
DEBUG [HostNameResolver] 20 Ago 2010 13:43:07.716 : Resolving ...
DEBUG [HostNameResolver] 20 Ago 2010 13:43:07.820 : ... resolved to ...
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:08.161 : Setting socket timeout=120000
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:08.174 : Command encoding=System.Text.ASCIIEncoding
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:08.176 : StrictReturnCodes=False
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:08.529 : 220 Precise/RTCS FTP Ready
DEBUG [FTPConnection] 20 Ago 2010 13:43:08.531 : Connected to ... (instance=0)
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:08.535 : ---> USER test
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:08.891 : 230 Logged in
DEBUG [FTPConnection] 20 Ago 2010 13:43:08.891 : Successfully logged in
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:08.892 : ---> TYPE I
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:09.235 : 200 Type OK
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:09.236 : ---> PWD
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:09.637 : 257 "\" is currently working directory
DEBUG [FTPConnection] 20 Ago 2010 13:43:09.639 : DownloadFile(c:\nivus.txt,NIVUSXXX.TXT)
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:09.677 : NewActiveDataSocket(0)
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:09.690 : ---> PORT 10,0,0,20,234,163
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:10.015 : 200 Port command okay
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:10.016 : ---> RETR NIVUSXXX.TXT
DEBUG [FTPControlSocket] 20 Ago 2010 13:43:10.434 : 150 Opening data connection for RETR (...2472)
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : Caught exception
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : System.IO.IOException: Failed to accept connection within timeout period (120000)
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.StandardSocket.Accept(Int32 timeout)
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPActiveDataSocket.AcceptConnection()
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPActiveDataSocket.get_DataStream()
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPClient.GetInputStream()
ERROR [FTPClient] 20 Ago 2010 13:45:11.991 : at EnterpriseDT.Net.Ftp.FTPClient.GetBinary(String localPath, String remoteFile)
DEBUG [FTPControlSocket] 20 Ago 2010 13:45:12.037 : Setting socket timeout=500
ERROR [FTPControlSocket] 20 Ago 2010 13:45:13.110 : Read failed ('' read so far)
WARN [FTPClient] 20 Ago 2010 13:45:13.110 : ReadReply failed
WARN [FTPClient] 20 Ago 2010 13:45:13.110 : EnterpriseDT.Net.Ftp.ControlChannelIOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.


I replaced some sensitive data with "..."


I also deactivated the computers firewall just to be sure that no ports where being blocked, but the result was the same.
0 votes
by (162k points)
The command being sent to the server is:

PORT 10,0,0,20,234,163

That means connect to me on 10.0.0.20.

That's an internal network address - is that reachable by the server?
0 votes
by (400 points)
Yes, that IP is reachable.

I just made another test to put any firewall out of the question. I connected a 3G pen on my laptop and with the firewall disabled, I still got the same error if I run the .Net Service application, and all works well if I run the .Net Windows application.

ERROR [FTPClient] 26 Ago 2010 14:43:30.888 : EnterpriseDT.Net.Ftp.ControlChannelIOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed


The code on both applications is exactly the same, why is this failing?

Categories

...