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


Sign In
Create Account


Back to top









