private void startFtp()
{
Api.WaitWindow("Connexion au serveur FTP en cours...");
ftp = new MercatorFtp.Ftp("ftp.host.com", "login", "password");
if (!ftp.Connect())
{
Api.Stop(ftp.LastError);
ftp.Dispose();
ftp = null;
Api.WaitClear();
return;
}
Api.WaitWindow("Upload FTP en cours...");
if (!ftp.PutFileAsync(targetDir + _dr_dest["d_newid"].ToString() + ".zip", @"_pub\wwwroot_www.mercator.eu\dealerzone\masters\" + _dr_dest["d_newid"].ToString() + ".zip", ftpProgressChanged, ftpProgressCompleted, out ftpAsyncUploader))
{
Api.Stop(ftp.LastError);
ftp.Dispose();
ftp = null;
Api.WaitClear();
return;
}
Cursor = System.Windows.Forms.Cursors.WaitCursor;
progressBar14.Value = 0;
progressBar14.Visible = true;
buttonCancelUpload.Enabled = true;
}
private void ftpProgressChanged(object sender, ProgressChangedEventArgs e)
{
labelProgress.Text = e.UserState.ToString();
progressBar14.Value = e.ProgressPercentage;
}
void ftpProgressCompleted(object sender, RunWorkerCompletedEventArgs e)
{
buttonCancelUpload.Enabled = false;
Cursor = System.Windows.Forms.Cursors.Default;
Api.WaitClear();
progressBar14.Visible = false;
if (string.IsNullOrEmpty(ftp.LastError))
{
done14 = true;
ici continuer le code : le transfert a été effectué sans erreur
}
else
{
Api.Stop(ftp.LastError);
}
ftp.Dispose();
ftp = null;
ftpAsyncUploader.Dispose();
ftpAsyncUploader = null;
}
private void buttonCancelUpload_Click(object sender, EventArgs e)
{
if (ftpAsyncUploader != null)
{
ftpAsyncUploader.CancelAsync();
buttonCancelUpload.Enabled = false;
labelProgress.Text = "FTP upload canceled !";
}
}