Jump to content

Displaying responce during FTP Upload

- - - - -

  • Please log in to reply
No replies to this topic

#1
aakinn

aakinn

    Newbie

  • Members
  • PipPip
  • 24 posts
Im currently writing a little interface which acts as an FTP client. I have the following code when it comes to uploading a file

private void Upload(string filename)

      {

         FileInfo fileInf = new FileInfo(filename);

         string uri = "ftp://" + ftpHost + "/" + txtUpload.Text + "/" + fileInf.Name;

         FtpWebRequest reqFTP;


         reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpHost + "/" + txtUpload.Text + "/" + fileInf.Name));


         reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

         reqFTP.KeepAlive = false;

         reqFTP.Method = WebRequestMethods.Ftp.UploadFile;


         reqFTP.UseBinary = true;


         // tell server size of the uploaded file

         reqFTP.ContentLength = fileInf.Length;


         // The buffer size is set to 2kb

         int buffLength = 2048;

         byte[] buff = new byte[buffLength];

         int contentLen;


         // read file to be uploaded

         FileStream fs = fileInf.OpenRead();


         try

         {

            Stream strm = reqFTP.GetRequestStream();


            // read stream 2kb at a time

            contentLen = fs.Read(buff, 0, buffLength);


            while (contentLen != 0)

            {     //FtpWebResponse responce = new FtpWebResponse;

               

               strm.Write(buff, 0, contentLen);

               contentLen = fs.Read(buff, 0, buffLength);

            }


            strm.Close();

            fs.Close();

            MessageBox.Show("File uploaded");


         }

         catch (Exception ex)

         {

            MessageBox.Show(ex.Message, "Upload Error");

         }

      }

The code works fine but what Id like to do is as the file is uploading display a message box with perhaps the progress of the upload or feedback from the server.

Help would be much appreciated




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users