Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
21.8k views
in .NET FTP by (320 points)
Hi all,

We're uploading several csv files to a remote server that requires active transfer mode. I've also tested this with our FTP server; passive mode works but active mode fails with this error message:

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

It seems the Port command never reaches the remote host. In the log, his is what is sent just before the error (IP masked for obvious reasons):

FTP command sent: ---> PORT XXX,XX,XX,XXX,9,222

I've also tested both modes manually with FileZilla and can transfer in either mode successfully. I can't understand the problem.

The code (VB.NET) used to set up & perform the transfer is (called in the order it appears):

FTPConn.ServerAddress = FTPServerURI
FTPConn.ServerPort = FTPPort
FTPConn.Timeout = 300000
FTPConn.AutoLogin = False
FTPConn.UserName = FTPUserName
FTPConn.Password = FTPPassword
FTPConn.Connect()
FTPConn.Login()
FTPConn.ConnectMode = EnterpriseDT.Net.Ftp.FTPConnectMode.ACTIVE
FTPConn.TransferType = EnterpriseDT.Net.Ftp.FTPTransferType.ASCII
FTPUpload(CSVFilePath & AttendanceCSVFileName, FTPPath & AttendanceCSVFileName)

All the variables being assigned have valid values.

I'm stumped, any help is greatly appreciated

Thanks

18 Answers

0 votes
by (161k points)
Post the log file so we can see a bit better what is going on
0 votes
by (320 points)
Thanks Bruce, here's the log:

DEBUG [EnterpriseDT.Net.HostNameResolver] 16 Nov 2006 10:05:46.422 : XXX.XXX.XXX.XXX resolved to XXX.XXX.XXX.XXX
DEBUG [EnterpriseDT.Net.Ftp.FTPClient] 16 Nov 2006 10:05:46.422 : Connecting to XXX.XXX.XXX.XXX:21
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.438 : 220 Microsoft FTP Service
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.438 : Invoking delegate EnterpriseDT.Net.Ftp.FTPConnectionEventHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.438 : Finding MainWindowHandle
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : No MainWindowHandle found
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : Invoking delegate dynamically
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : Dynamic delegate invocation complete
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.454 : ---> USER xxxxxxx
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.454 : 331 Password required for sfitsp04.
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.454 : ---> PASS ********
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.454 : 230 User sfitsp04 logged in.
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : Invoking delegate EnterpriseDT.Net.Ftp.FTPLogInEventHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : Invoking delegate dynamically
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.454 : Dynamic delegate invocation complete
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.454 : ---> TYPE A
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.454 : 200 Type set to A.
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.469 : Invoking delegate EnterpriseDT.Net.Ftp.FTPFileTransferEventHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.469 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.469 : Invoking delegate dynamically
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:46.469 : Dynamic delegate invocation complete
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.469 : NewActiveDataSocket(0)
INFO [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.469 : Forcing use of fixed IP for PORT command
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:46.469 : ---> PORT XXX,XXX,XXX,XXX,13,37
ERROR [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:47.939 : Failed to create listening socket : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadLine()
at EnterpriseDT.Net.Ftp.FTPControlSocket.ReadReply()
at EnterpriseDT.Net.Ftp.FTPControlSocket.SendCommand(String command)
at EnterpriseDT.Net.Ftp.FTPControlSocket.SetDataPort(IPEndPoint ep)
at EnterpriseDT.Net.Ftp.FTPControlSocket.NewActiveDataSocket(Int32 port)
CAUSED BY:
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
ERROR [EnterpriseDT.Net.Ftp.FTPClient] 16 Nov 2006 10:05:48.017 : Caught exception : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at EnterpriseDT.Net.Ftp.FTPControlSocket.NewActiveDataSocket(Int32 port)
at EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocketActive()
at EnterpriseDT.Net.Ftp.FTPControlSocket.CreateDataSocket(FTPConnectMode connectMode)
at EnterpriseDT.Net.Ftp.FTPClient.InitPut(String remoteFile, Boolean append)
at EnterpriseDT.Net.Ftp.FTPClient.PutASCII(Stream srcStream, String remoteFile, Boolean append)
CAUSED BY:
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : Invoking delegate EnterpriseDT.Net.Ftp.FTPFileTransferEventHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : Invoking delegate dynamically
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : Dynamic delegate invocation complete
DEBUG [EnterpriseDT.Net.Ftp.FTPControlSocket] 16 Nov 2006 10:05:48.017 : ---> QUIT
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : Invoking delegate EnterpriseDT.Net.Ftp.FTPConnectionEventHandler
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : No GUI control
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : Invoking delegate dynamically
DEBUG [EnterpriseDT.Net.Ftp.FTPConnection] 16 Nov 2006 10:05:48.017 : Dynamic delegate invocation complete
0 votes
by (51.1k points)
This could be caused by a firewall interfering with the incoming data connection. Have you tried using passive mode?

- Hans (EDT)
0 votes
by (320 points)
Hans, thanks for the reply. Yes, passive mode works fine but for the production version, files will be transferred to a service that requires active mode. I have tested the firewall question by using an FTP client (FileZilla) to transfer files in both modes directly from the server the application is running on. Both modes work without a problem so I can't see where it would be a firewall issue.

I'm now taking the approach of instantiating the FTP client rather than using the toolbox component. So far, I am still having some issues. If you can think of any other reason the above may be failing, please let me know.

Thanks

David
0 votes
by (51.1k points)
It could be that the firewall is manipulating the argument of the PORT command and thus directing the client to the wrong IP address. Try using setting FTPClient.ActiveIPAddress property to the address of the server. This causes the client to ignore the IP address part of the PORT argument and use the setting instead.

- Hans (EDT)
0 votes
by (320 points)
Thanks again Hans,

I already tried the ActiveIPAddress property because I happened to notice that the control seemed to be picking up the IP address of my development machine. I set it to the IP of the application server and it still didn't work. However, the good news is that by not using the drag-and-drop component and instantiating an instance of the client instead, it now works.

I'm still very curious as to why the component approach was unsuccessful. You still may wish to look into this further for future reference.

Thanks again,

David
0 votes
by (51.1k points)
Yes, I'm certainly very interested in that. Would it be possible for you to send us the logs - one for FTPClient and one for FTPConnection? If you could e-mail them to support@enterprisedt..., we'd be very grateful.

- Hans (EDT)
0 votes
by (320 points)
Hans,

I've emailed the log file with notations showing when I stopped using the drag-and-drop component and when I started using the instantiated client. Please let me know if you find anything.

Thanks again for your help.
0 votes
by (161k points)
Many thanks for sending it. Nice to have helpful users :)
0 votes
by (161k points)
Are you setting FTPConnection.PublicIPAddress?

Somehow this is getting set to 150.xxx.xxx.xxx. This is used in the PORT command to send the IP address to the server that it must connect to. The server can't connect to this IP address.

With FTPClient, the server is successfully connecting to the sent (via PORT) IP address of 172.xxx.xxx.xxx, which I assume is the IP address of the machine your client is running on.

Categories

...