Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.6k views
in .NET FTP by (200 points)
I'm using the edtFTPnet within a C# dll, therefore I'm instatiating the FTPConnection myself rather than using it through a form.

I can get it to upload file after file, but occasionally I get the following exception...
Exception: "Unable to write data to the transport connection."
Inner Exception: "An existing connection was forcibly closed by the remote host"

Can anybody explain why I'm getting this Exception, or what extra information I can provide to help work it out?

This is the code I'm using
try
{
   ftp.ServerAddress = "www.*****.co.uk";
   ftp.ServerDirectory = "/*****/";
   ftp.ServerPort = 21;
   ftp.ConnectMode = EnterpriseDT.Net.Ftp.FTPConnectMode.ACTIVE;
   ftp.TransferType = EnterpriseDT.Net.Ftp.FTPTransferType.BINARY;
   ftp.AutoLogin = true;
   ftp.UserName = "*****";
   ftp.Password = "*****";
   ftp.Timeout = 300000;

   ftp.Connect();
   if ( ftp.Exists( remoteFileName ) ) 
      ftp.DeleteFile( remoteFileName );
   ftp.UploadFile( fileName, remoteFileName );
   ftp.Close();
}
catch (Exception obException)
{
   if ( ftp.IsConnected )
      ftp.Close();
}

Many thanks,
Tom :-)

4 Answers

0 votes
by (51.6k points)
Could you please enable logging and post the log?

- Hans (EDT)
0 votes
by (200 points)
Thanks for the reply :)

As is usual in these situations, the exception is now not happening.
I will leave the logging turned on, and if it happens again I'll post back with the offending section of the log.

Cheers,
Tom :)
0 votes
by (200 points)
I've now got the log output of the error (I have obviously blocked out sensitive information)...

ALL [FTPConnection] 2 Mar 2007 16:42:30.250 : Invoking delegate EnterpriseDT.Net.Ftp.FTPConnectionEventHandler
ALL [FTPConnection] 2 Mar 2007 16:42:30.250 : Finding MainWindowHandle
ALL [FTPConnection] 2 Mar 2007 16:42:30.265 : MainWindowHandle found
ALL [FTPConnection] 2 Mar 2007 16:42:30.265 : Have GUI control
ALL [FTPConnection] 2 Mar 2007 16:42:30.265 : GUI control invocation required
ALL [FTPConnection] 2 Mar 2007 16:42:30.265 : Invoking delegate asynchronously using GUI control
DEBUG [HostNameResolver] 2 Mar 2007 16:42:30.265 : www.*****.co.uk resolved to 87.***.***.***
DEBUG [FTPClient] 2 Mar 2007 16:42:30.265 : Connecting to 87.***.***.***:21
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.375 : 220 Microsoft FTP Service
ALL [FTPConnection] 2 Mar 2007 16:42:30.375 : Invoking delegate EnterpriseDT.Net.Ftp.FTPConnectionEventHandler
ALL [FTPConnection] 2 Mar 2007 16:42:30.375 : Have GUI control
ALL [FTPConnection] 2 Mar 2007 16:42:30.375 : GUI control invocation required
ALL [FTPConnection] 2 Mar 2007 16:42:30.375 : Invoking delegate asynchronously using GUI control
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.375 : ---> USER *****
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.453 : 331 Password required for ******.
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.453 : ---> PASS ********
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.515 : 230 User ***** logged in.
DEBUG [FTPConnection] 2 Mar 2007 16:42:30.515 : Successfully logged in
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.515 : ---> TYPE I
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.609 : 200 Type set to I.
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.609 : ---> PWD
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.656 : 257 "/" is current directory.
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.656 : ---> CWD FTP/WebShopServer/TEST/
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.734 : 250 CWD command successful.
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:30.734 : ---> PWD
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.031 : 257 "/FTP/WebShopServer/TESTSHOP" is current directory.
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.031 : ---> SIZE WebShopAttachFiles_DataUploadAttachments_1.zip
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.093 : 550 WebShopAttachFiles_DataUploadAttachments_1.zip: The system cannot find the file specified. 
ALL [FTPConnection] 2 Mar 2007 16:42:31.093 : Invoking delegate EnterpriseDT.Net.Ftp.FTPFileTransferEventHandler
ALL [FTPConnection] 2 Mar 2007 16:42:31.093 : Have GUI control
ALL [FTPConnection] 2 Mar 2007 16:42:31.093 : GUI control invocation required
ALL [FTPConnection] 2 Mar 2007 16:42:31.093 : Invoking delegate synchronously using GUI control
ALL [FTPConnection] 2 Mar 2007 16:42:31.125 : Delegate invocation complete
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.125 : NewActiveDataSocket(0)
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.125 : ---> PORT 192,***,****,****,****
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.171 : 200 PORT command successful.
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.171 : ---> STOR WebShopAttachFiles_DataUploadAttachments_1.zip
DEBUG [FTPControlSocket] 2 Mar 2007 16:42:31.250 : 150 Opening BINARY mode data connection for WebShopAttachFiles_DataUploadAttachments_1.zip.
DEBUG [FTPActiveDataSocket] 2 Mar 2007 16:42:31.343 : AcceptConnection() succeeded
ERROR [FTPClient] 2 Mar 2007 16:42:31.343 : Caught exception : System.IO.IOException: Unable to write data to the transport connection.
System.IO.IOException: Unable to write data to the transport connection.
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.BinaryWriter.Write(Byte[] buffer, Int32 index, Int32 count)
   at EnterpriseDT.Net.Ftp.FTPClient.PutBinary(Stream srcStream, String remoteFile, Boolean append, Boolean alwaysCloseStreams)
CAUSED BY:
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
ALL [FTPConnection] 2 Mar 2007 16:42:31.343 : Invoking delegate EnterpriseDT.Net.Ftp.FTPFileTransferEventHandler
ALL [FTPConnection] 2 Mar 2007 16:42:31.343 : Have GUI control
ALL [FTPConnection] 2 Mar 2007 16:42:31.343 : GUI control invocation required
ALL [FTPConnection] 2 Mar 2007 16:42:31.343 : Invoking delegate asynchronously using GUI control


Does that give you any clue as to what's happening - and more importantly, if I can stop it happening?
It happens if I'm using a single FTPConnection or multiple FTPConnections (one per managed thread)
It's not a persistant error, but persistant to be really, really annoying.

Cheers,
Tom :)
0 votes
by (162k points)
It isn't clear why but the FTP server closed the data connection before transferring any data. There may be more information in the server logs.

Categories

...