这是我的代码
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;
}
我什么时候用
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");
}
}
单击 button6 时收到的消息是“Workker run!!!” 之后什么都没有,***我的光标仍然是默认的(永远不会改变!!!,为什么?),我是 backgroundWorker 的超级新手对不起:(请帮帮我....