Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.9k views
in .NET FTP by (620 points)
I am trying to wite an automated ftp program that can run without intervention. I have everything working but have one problem every other time I connect it will transfer a few files then throw this exception to a message box on the screen. Do you have any ideas on how I could avoid this message going to the UI.

[quote]System.IO.IOException: Unable to read data from the transport connection. ---> System.Net.Sockets.SocketException: 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
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)
--- End of inner exception stack trace ---
at EnterpriseDT.Net.Ftp.FTPClient.InitGet(String remoteFile)
at EnterpriseDT.Net.Ftp.FTPClient.GetBinary(String localPath, String remoteFile)
at EnterpriseDT.Net.Ftp.FTPClient.Get(String localPath, String remoteFile)
at CNFTP2.CNFTP2.downLoadFiles() [/quote]

4 Answers

0 votes
by (162k points)
Put a try/catch block around your code to catch System.Exception.

I am trying to wite an automated ftp program that can run without intervention. I have everything working but have one problem every other time I connect it will transfer a few files then throw this exception to a message box on the screen. Do you have any ideas on how I could avoid this message going to the UI.

0 votes
by (620 points)
Yep! Tried that!
Still throwing a message box to the screen saying unhandled exception.

Is there a specific way I should try to catch this exception?
[code]
string remoteFile = uploadFile.Name;
try
{
this.ftpClient.TransferType =
EnterpriseDT.Net.Ftp.FTPTransferType.BINARY;
this.ftpClient.Put( sendFile, remoteFile );
}
catch(FTPException exput)
{
Console.WriteLine("PUT Error: " + exput.Message.ToString());
LOG.WriteLine("PUT Error: " + exput.Message.ToString());
this.m_ErrorCount++;
return;
}[/code]
0 votes
by (162k points)
Are you catching Exception (rather than FTPException)?

Yep! Tried that!
Still throwing a message box to the screen saying unhandled exception.

Is there a specific way I should try to catch this exception?
0 votes
by
Yes, I am catching for Exception. That code was changed to FTP Exception when I was trying to figure out this problem.

It seems to be a Socket connection problem, but Is there a way to test the socket to see if it is open and connected?

Categories

...