First of all i download a three files from different ftp servers while downloading one server is shutdown but i didn't get Exception
try
{
Stream strLocal;
WebProxy wp = new WebProxy();
wp.UseDefaultCredentials = true;
FtpWebRequest request = FtpWebRequest.Create(FTPAddress) as FtpWebRequest;
request.Proxy = wp;
request = FtpWebRequest.Create(FTPAddress) as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Proxy = wp;
request.ServicePoint.ConnectionLimit = 10;
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
request.ContentOffset = StartPoint;
Stream reader = request.GetResponse().GetResponseStream();
byte[] buffer = new byte[1048576];
if (!File.Exists(filename))
{
strLocal = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
}
else
{
File.Delete(filename);
strLocal = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
}
int bytesSize = 0;
while ((bytesSize = reader.Read(buffer, 0, buffer.Length)) > 0)
{
if ((strLocal.Length + bytesSize) < length)
{
strLocal.Write(buffer, 0, bytesSize);
this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, length, i, Partfilename, bytesSize });
}
else
{
long Valtowrite = (strLocal.Length + bytesSize) - length;
Valtowrite = bytesSize - Valtowrite;
strLocal.Write(buffer, 0, (int)Valtowrite);
this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, length, i, Partfilename, bytesSize });
break;
}
}
strLocal.Close();
}
catch (System.Net.WebException ex)
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "There was an error connecting to the FTP Server.");
}
Thanks in Advance
kalai