Wednesday, 11 September 2013

File on FTP exist before download

File on FTP exist before download

i have code, where i downloading file from FTP..I try to check if the file
exist...Have you any idea? This is sample of my code:
var c2 = (counter2).ToString().PadLeft(5, '0');
FtpWebRequest request =
FtpWebRequest)WebRequest.Create((FtpNOHELZmeny) + "o" + (c2) + ".xml");
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(**, **);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
StreamWriter writer = new StreamWriter((backup) + "o" + (c2) + ".xml");
writer.Write(reader.ReadToEnd());
FileInfo f = new FileInfo((backup) + "o" + (c2) + ".xml");
long original_vel = f.Length;
long ftp_vel = request.ContentLength;
if (original_vel == ftp_vel)
{
Console.WriteLine("OK{0}", response.StatusDescription);
reader.Close();
writer.Close();
response.Close();
XDocument doc = XDocument.Load((backup) + "orders" + (c2) + ".xml");
var NUMBER = doc.Descendants("NUMBER");
......
Console.ReadLine();
Console.WriteLine("message... {0}", response.StatusDescription);
counterchyba2 = 0;
counter2++;
}

No comments:

Post a Comment