Hello,
FTPWebRequest.KeepAlive property will let you specify a boolean value whether the control connection to the FTP server is closed after the request completes.
FTPWebRequest.ReadWriteTimeout property will let you specify the number of milliseconds before the reading or writing times out. The default value is 300,000 milliseconds (5 minutes).
If your file are very big and/or you have a slow internet connection this can be a problem.
You can try upload the files asynchronously.
Please read the class documentation
here.
Sample code to upload a file to a ftp server:
FtpWebRequest ftpRequest;
FtpWebResponse ftpResponse;
try
{
this.ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://ServerIP/FileName"));
this.ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
this.ftpRequest.Proxy = null;
this.ftpRequest.UseBinary = true;
this.ftpRequest.Credentials = new NetworkCredential("UserName", "Password");
FileInfo ff = new FileInfo("File Local Path With File Name");
byte[] fileContents = new byte[ff.Length];
using (FileStream fr = ff.OpenRead())
{
fr.Read(fileContents, 0, Convert.ToInt32(ff.Length));
}
using (Stream writer = ftpRequest.GetRequestStream())
{
writer.Write(fileContents, 0, fileContents.Length);
}
this.ftpResponse = (FtpWebResponse)this.ftpRequest.GetResponse();
Response.Write(this.ftpResponse.StatusDescription);
}
catch (WebException webex)
{
this.Message = webex.ToString();
}
Cheers,
JAFC