So... I have this program that has been working for some years now. I connect to an ftp server, list the files in the directory, check if they already exist in my local directory and then downloads the ones who doesn't.
Suddenly, a few weeks ago it stopped downloading files. It couldn't connect to ftp server. Around the same time the network administrators changed some routers and did some maintenance. According to them there is no firewall or virus program stopping the connection.
I use FtpClient.cs : This is part of my code :
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = (BackgroundWorker)sender;
SqlConnection con = new SqlConnection(ConString);
con.Open();
if (FbackgroundWorker1.CancellationPending) { e.Cancel = true; return; }
foreach (DataRow ship in s_dt.Rows)
{
worker.ReportProgress(2100, ship["name"].ToString());
FtpClient ftpc = new FtpClient(ship["FTP"].ToString().Trim(), userName, userPassword, timeOut, ftpPort);
try
{
worker.ReportProgress(1000, "Login to FTP Server on " + ship["name"].ToString().Trim());
ftpc.Login();
if (FbackgroundWorker1.CancellationPending) { e.Cancel = true; ftpc.Close(); return; }
worker.ReportProgress(1000, "Change Directory to: " + pathName);
ftpc.ChangeDir(pathName);
if (FbackgroundWorker1.CancellationPending) { e.Cancel = true; ftpc.Close(); return; }
worker.ReportProgress(1000, "Download file list");
string[] listOfFiles = ftpc.GetFileList();
if (FbackgroundWorker1.CancellationPending) { e.Cancel = true; ftpc.Close(); return; }
worker.ReportProgress(2000, listOfFiles);
ftpc.Close();
worker.ReportProgress(1000, "Close connect to FTP Server on " + ship["name"].ToString().Trim());
worker.ReportProgress(1000, "Select new files");
string[] LMF = myCheckList(listOfFiles, ship["id"].ToString().Trim());
worker.ReportProgress(2001, LMF);
int numberOfFiles = LMF.Count();
worker.ReportProgress(3000, numberOfFiles);
int ret = 0;
worker.ReportProgress(1000, "Login to FTP Server");
ftpc.Login();
if (FbackgroundWorker1.CancellationPending) { e.Cancel = true; ftpc.Close(); return; }
foreach (string zbior in LMF)
{
worker.ReportProgress(2101, zbior);
worker.ReportProgress(1000, "Change Directory to: " + pathName + @"\" + zbior);
ftpc.ChangeDir(pathName);
ftpc.ChangeDir(zbior);
if (FbackgroundWorker1.CancellationPending) { e.Cancel = true; ftpc.Close(); return; }
TimeSpan ts = DateTime.UtcNow - new DateTime(2008, 1, 1, 0, 0, 0, 0);
string timeStamp = Convert.ToInt64(ts.TotalMilliseconds).ToString();
string fullFileName = impPathName + @"\ship" + ship["id"] + @"\TREND24(F)(fileID" + timeStamp + @")(" + zbior + @").SKV";
worker.ReportProgress(1000, "Download file: " + fullFileName);
ftpc.Download("TREND24.SKV", fullFileName, true);
worker.ReportProgress(1000, "Test file: " + zbior);
StreamReader sr = new StreamReader(fullFileName);
string fileToTest = sr.ReadToEnd();
if (fileToTest.Contains("END"))
{
SqlCommand command = new SqlCommand("INSERT INTO [dbo].[datafiles](ship_id, fileName, dY, dM, dD, [DownloadDate], [ident] ) VALUES ("
+ ship["id"] + ", '"
+ zbior + "', "
+ zbior.Substring(0, 2) + ", "
+ zbior.Substring(2, 2) + ", "
+ zbior.Substring(4, 2) + ", '"
+ DateTime.Now.ToString(dateTimeFormat) + "', '"
+ timeStamp + "' )", con);
ret = ret + command.ExecuteNonQuery();
FbackgroundWorker1.ReportProgress(ret);
worker.ReportProgress(1000, "Test OK");
}
else
{
worker.ReportProgress(1000, "file: " + zbior + " not contain END");
}
}
if (FbackgroundWorker1.CancellationPending) { e.Cancel = true; ftpc.Close(); return; }
worker.ReportProgress(1000, "Close connect to FTP");
worker.ReportProgress(2102, "Clear file list");
ftpc.Close();
}
catch (Exception ex)
{
ftpc.Close();
worker.ReportProgress(1000, "Close connect to FTP error: " + ex.Message);
}
finally
{
worker.ReportProgress(1000, "Problem with connect to FTP ");
}
}
if (con != null) con.Close();
}
I ran breakpoints while debugging and this is the errors i have:
”An established connection was aborted by the software in your host machine”, with ErrorCode 10053
and
clientSocket.EnableBroadcast threw an exception of type System.Net.Sockets.SocketEcxeption. ”An unknown, invalid or unsupported option or level was specified in a getsockopt or setsockopt call”. ErrorCode 10042. SocketErrorCode: ProtocolOption.
and
clientSocket.MulticastLoopback threw an exception of type System.Net.Sockets.SocketEcxeption. ”An invalid argument was supplied”. NativeErrorCode 10022
Need help !
thanks