Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make FTP upload function with backgroundWorker
    primarykey
    data
    text
    <p>here is my code</p> <pre><code>public bool FTPUploadFunct(string uploadto2, string newskinlocation2) { bool FTPUploadFunct = true; toolStripStatusLabel1.Text = "uploading...."; MessageBox.Show("uploading"); try { //delete old file FtpWebRequest requestFileDelete = (FtpWebRequest)WebRequest.Create(uploadto2); requestFileDelete.Credentials = new NetworkCredential("FTPUser20", "1234"); requestFileDelete.Method = WebRequestMethods.Ftp.DeleteFile; FtpWebResponse responseFileDelete = (FtpWebResponse)requestFileDelete.GetResponse(); //upload new file FtpWebRequest requestFTPUploader = (FtpWebRequest)WebRequest.Create(uploadto2); requestFTPUploader.Credentials = new NetworkCredential("FTPUser20", "1234"); requestFTPUploader.Method = WebRequestMethods.Ftp.UploadFile; FileInfo fileInfo = new FileInfo(newskinlocation2); FileStream fileStream = fileInfo.OpenRead(); int bufferLength = 2048; byte[] buffer = new byte[bufferLength]; Stream uploadStream = requestFTPUploader.GetRequestStream(); int contentLength = fileStream.Read(buffer, 0, bufferLength); while (contentLength != 0) { uploadStream.Write(buffer, 0, contentLength); contentLength = fileStream.Read(buffer, 0, bufferLength); } uploadStream.Close(); fileStream.Close(); requestFTPUploader = null; } catch (WebException ex) { FTPUploadFunct = false; String status = ((FtpWebResponse)ex.Response).StatusDescription; MessageBox.Show(status); int errorNumber = (int)ex.Status; if (errorNumber == 550) { MessageBox.Show("550"); }; } return FTPUploadFunct; } </code></pre> <p>I use it when</p> <pre><code>private void button6_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; uploadto = ("ftp://" + severip + ":21/" + "IMG/" + username + ".png"); backgroundWorker1.RunWorkerAsync(); Cursor.Current = Cursors.Default; } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { MessageBox.Show("Workker run!!!"); bool resualtUp = FTPUploadFunct(uploadto, newskinlocation); if (resualtUp == true) { MessageBox.Show("True"); } else { MessageBox.Show("False"); } } </code></pre> <p>message I get when I click button6 is "Workker run!!!" and nothing after that,***My cursor is still default(Never change!!!, why ?), I'm super newbie for backgroundWorker sorry :( please help me....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload