0 votes
by (120 points)
edited

hi there .. i am developing a web application and need to show the progress, i send a thred to threadpool then need control of progress event and progress value ... i define some control class ..............//// a button click raise the upload if (((StatusFtpUpload)Application["ftpupload"]).Running == false){ ThreadPool.QueueUserWorkItem(new WaitCallback(FtpUpload), ((StatusFtpUpload)Application["cpx_ftpupload"])); }

    // the procedure polled in threadpool that need update the stateInfo.progress value
    static void FtpUpload(Object stateInfo) {

        StatusFtpUpload status = (StatusFtpUpload)stateInfo;
        Rebex.Net.Ftp ftpcontrol = new Rebex.Net.Ftp();


        try {



            ftpcontrol.Connect(status.FtpData.IpServer);
            ftpcontrol.Login(status.FtpData.User, status.FtpData.Password);
            ftpcontrol.PutFiles(status.FtpData.LocalFolder, status.FtpData.RemotePath, FtpBatchTransferOptions.Recursive, FtpActionOnExistingFiles.OverwriteAll);
     //try do someting with events but dont find how control the progress nither value

        }
        finally { 
            status.Running = false; 
        }
Applies to: Rebex FTP/SSL

1 Answer

+1 vote
by (70.2k points)
edited

All you need is to register the Ftp.BatchTransferProgress event and specify appropriate method of your StatusFtpUpload class. You can try something like this:

class StatusFtpUpload {
    // ... add this method to your existing StatusFtpUpload class
    public void BatchTransferProgress(object sender, FtpBatchTransferProgressEventArgs e) {
        // update internal values
        this.progress = e.ProcessedPercentage;
    }
}

// the procedure polled in threadpool that need update the stateInfo.progress value
static void FtpUpload(Object stateInfo) {
    StatusFtpUpload status = (StatusFtpUpload)stateInfo;
    Rebex.Net.Ftp ftpcontrol = new Rebex.Net.Ftp();

    // register status.BatchTransferProgress method
    ftpcontrol.BatchTransferProgress += new FtpBatchTransferProgressEventHandler(status.BatchTransferProgress);

    try {
        ftpcontrol.Connect(status.FtpData.IpServer);
        ftpcontrol.Login(status.FtpData.User, status.FtpData.Password);
        ftpcontrol.PutFiles(status.FtpData.LocalFolder, status.FtpData.RemotePath, FtpBatchTransferOptions.Recursive, FtpActionOnExistingFiles.OverwriteAll);
    }
    finally { 
        status.Running = false; 
    }
by (120 points)
lukas thanks for answer me ... but status is not a rebex.ftp derived class. i define a method: static void progressupdate(object state, FtpBatchTransferProgressEventArgs ev) { ((StatusInfo)state).Progress = ev.ProcessedPercentage; } then at method make this that u say: ftpcontrol.BatchTransferProgress += new FtpBatchTransferProgressEventHandler(progressupdate); but ... how send parameters? thanks againg
by (70.2k points)
There is no need for the StatusFtpUpload class to be derived from the Rebex.Net.Ftp class. You can register ANY method in the Ftp.BatchTransferProgress event (even the method of your class) as shown in my answer. Just try it ;-)
...