Uploading file using FtpWebRequest

D

Deep

Dear Friends
I am using FtpWebRequest to upload file. But it is slow Can you
please provide me any method to do it fast
this is my code
public string uploadFileUsingFTP(byte[] fileStream,
CashmanUpload.CashmanUploadService.EventImageVariable eventVariable)
{
// get the ftppath from config file and the image loctaion
//from input parameters
string CompleteFTPPath = eventVariable.UploadImagepath +
eventVariable.ImageName;
// set the ftp userid
string UName =
Convert.ToString(eventVariable.refFTPUserID);
// set the ftp password
string PWD =
Convert.ToString(eventVariable.refFTPPassword);
string retrunvalue = "";
CashmanUpload.CashmanUploadService.UploadService
uploadService =
new CashmanUpload.CashmanUploadService.UploadService();

try
{
if (!
uploadService.CheckImageExitsservice(eventVariable))
{
//Create a FTP Request Object and Specfiy a
Complete Path
FtpWebRequest reqObj =
(FtpWebRequest)FtpWebRequest.Create(new Uri(CompleteFTPPath));
reqObj.KeepAlive = false;
// set the maximum timeout for upload the heavy
images
reqObj.Timeout = 10000000;
// set the maximum write timeout for upload the
heavy images
reqObj.ReadWriteTimeout = 10000000;
//If you want to access Resourse Protected You
need to give User Name and PWD
reqObj.Credentials = new NetworkCredential(UName,
PWD);
//Call A FileUpload Method of FTP Request
Object
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
// Copy the contents of the file to the request
stream.
reqObj.ContentLength = fileStream.Length;
// create the Stream object to write the file on
FTP
Stream requestStream = reqObj.GetRequestStream();
requestStream.Write(fileStream, 0,
fileStream.Length);
requestStream.Close();
// get the final response
FtpWebResponse response =
(FtpWebResponse)reqObj.GetResponse();
response.Close();
// if sucessfull the reurn OK
retrunvalue = "OK";
}
else
{
// else retrun NOTDONE to retry the same image
again
retrunvalue = "NOTDONE";
}
}
catch (Exception ex)
{
UserExceptionLog.CreateExceptionLog(ex);
//MessageBox.Show(ex.Message + " function name is
uploadFileUsingFTP 731");
}
return retrunvalue;
}
 
G

Guest

Dear Friends
  I am using FtpWebRequest to upload file. But it is slow Can you
please provide me any method to do it fast
this is my code
  public string uploadFileUsingFTP(byte[] fileStream,
CashmanUpload.CashmanUploadService.EventImageVariable eventVariable)
        {
            // get the ftppath from config file and the image loctaion
            //from input parameters
            string CompleteFTPPath = eventVariable.UploadImagepath +
                 eventVariable.ImageName;
            // set the ftp userid
            string UName =
Convert.ToString(eventVariable.refFTPUserID);
            // set the ftp password
            string PWD =
Convert.ToString(eventVariable.refFTPPassword);
            string retrunvalue = "";
            CashmanUpload.CashmanUploadService.UploadService
uploadService =
            new CashmanUpload.CashmanUploadService.UploadService();

            try
            {
                if (!
uploadService.CheckImageExitsservice(eventVariable))
                {
                    //Create a FTP Request Object and Specfiy a
Complete Path
                    FtpWebRequest reqObj =
(FtpWebRequest)FtpWebRequest.Create(new Uri(CompleteFTPPath));
                    reqObj.KeepAlive = false;
                    // set the maximum timeout for upload the heavy
images
                    reqObj.Timeout = 10000000;
                    // set the maximum write timeout for upload the
heavy images
                    reqObj.ReadWriteTimeout = 10000000;
                    //If you want to access Resourse Protected You
need to give User Name and PWD
                    reqObj.Credentials = new NetworkCredential(UName,
PWD);
                    //Call A FileUpload Method of FTP Request
Object
                    reqObj.Method = WebRequestMethods.Ftp.UploadFile;
                    // Copy the contents of the file to the request
stream.
                    reqObj.ContentLength = fileStream.Length;
                    // create the Stream object to write the file on
FTP
                    Stream requestStream = reqObj.GetRequestStream();
                    requestStream.Write(fileStream, 0,
fileStream.Length);
                    requestStream.Close();
                    // get the final response
                    FtpWebResponse response =
(FtpWebResponse)reqObj.GetResponse();
                    response.Close();
                    // if sucessfull the reurn OK
                    retrunvalue = "OK";
                }
                else
                {
                    // else retrun NOTDONE to retry the same image
again
                    retrunvalue = "NOTDONE";
                }
            }
            catch (Exception ex)
            {
                UserExceptionLog.CreateExceptionLog(ex);
                //MessageBox.Show(ex.Message + "  function name is
uploadFileUsingFTP 731");
            }
            return retrunvalue;
        }

One of the problem could be a time to make connection to the FTP
server. Take a look at the following thread, maybe it will give you
some ideas
http://stackoverflow.com/questions/1016690/netftpwebrequest-how-to-improve-ftp-performance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top