private void FtpSession_FileTransferProgress(object sender, KCommon.Net.FTP.IFtpFileTransferArgs args) { try { double TotalSize = args.TotalBytes; TransferProgress = args.TotalBytesTransfered; if(LTransfer != 0) { TotalTransferProgress += (TransferProgress - LTransfer); } LTransfer = TransferProgress; // frmTS.pbCBar.Maximum = 100; // frmTS.pbCBar.Minimum = 0; // frmTS.pbTBar.Minimum = 0; // // frmTS.pbCBar.Value = CalculatePercentage(TransferProgress,TotalSize); // frmTS.pbTBar.Value = CalculatePercentage(TotalTransferProgress,TotalFileSize);//ConvertBytesToProgressBarInt(TotalTransferProgress); int TotalDownloadPercentage = 0; try { TotalDownloadPercentage = CalculatePercentage(TotalTransferProgress,TotalFileSize); } catch(Exception Err) { string peekError = Err.Message; } TransferDirection e = TransferDirection.Upload; if(args.TransferDirection == KCommon.Net.FTP.TransferDirection.Download) e = TransferDirection.Download; TransferResult TR = new TransferResult(); OysterTransferArguments ota = new OysterTransferArguments(args.LocalFileName, args.RemoteFileName,(double)args.TotalBytes,TransferProgress,TotalFileSize,TotalTransferProgress, e,args.TransferedPercentage,(int)TotalDownloadPercentage,TR); if(On_TransferProgress != null) On_TransferProgress(this,ota); string sCurrent = ConvertByteToString(TransferProgress); string sTotal = ConvertByteToString(TotalSize); // frmTS.pbTBar.Refresh(); string sDirection = "Download"; if(args.TransferDirection == KCommon.Net.FTP.TransferDirection.Upload) sDirection = "Upload"; // Msg(sDirection + " progress: " + ((double)(TransferProgress / 1024 / 1024)).ToString() + " of " + ((double)(TotalSize / 1024 / 1024)).ToString()); Msg(sDirection + " progress: " + sCurrent + " of " + sTotal); Application.DoEvents(); } catch(Exception Err) { //MessageBox.Show(Err.Message,"File Transfer Progress"); string p = Err.Message; } }
private void FtpSession_EndGetFile(object sender, KCommon.Net.FTP.IFtpFileTransferArgs args) { #region Send Download_End_Event long TotalDownloadPercentage = 0; try { //Only used during multiple file downloads/uploads TotalDownloadPercentage = CalculatePercentage(TotalTransferProgress,TotalFileSize); } catch(Exception Err) { string peekError = Err.Message; } try { if(args.TransferResult != null) { bTransferSuccess = args.TransferResult.IsSuccess; } else if(args.TransferedPercentage > 90) { bTransferSuccess = true; } else { bTransferSuccess = false; } } catch(Exception CErr) { string peekThisErr = CErr.Message; } try { TransferDirection e = TransferDirection.Upload; if(args.TransferDirection == KCommon.Net.FTP.TransferDirection.Download) e = TransferDirection.Download; TransferResult TR = new TransferResult(); OysterTransferArguments ota = new OysterTransferArguments(args.LocalFileName, args.RemoteFileName,(double)args.TotalBytes,TransferProgress,TotalFileSize,TotalTransferProgress, e,args.TransferedPercentage,(int)TotalDownloadPercentage,TR); if(On_Download_Complete != null) On_Download_Complete(this,ota); } catch(Exception PostError) { string peekError = PostError.Message; OysterTransferArguments Eota = new OysterTransferArguments(args); if(On_Upload_Complete != null) On_Upload_Complete(this,Eota); } #endregion Msg("Download complete."); DownloadingFile = false; TransferProgress = 0; m_ThreadTransferCompleteEvent.Set(); }
private void FtpSession_EndPutFile(object sender, KCommon.Net.FTP.IFtpFileTransferArgs args) { #region Send Upload_Begin_Event long TotalDownloadPercentage = 0; try { TotalDownloadPercentage = CalculatePercentage(TotalTransferProgress,TotalFileSize); } catch(Exception Err) { string peekError = Err.Message; } try { if(args.TransferResult != null) { bTransferSuccess = args.TransferResult.IsSuccess; } else if(args.TransferedPercentage > 90) { bTransferSuccess = true; } else { bTransferSuccess = false; } } catch(Exception CErr) { string peekThisErr = CErr.Message; } try { TransferDirection e = TransferDirection.Upload; TransferResult TR = null; if(args.TransferDirection == KCommon.Net.FTP.TransferDirection.Download) e = TransferDirection.Download; if(args.TransferResult != null) { TR = new TransferResult(args.TransferResult.FtpResponseCode, args.TransferResult.IsAborted,args.TransferResult.IsFailed,args.TransferResult.IsSuccess, args.TransferResult.Message); } else { TR = new TransferResult(0,false,false,false,"No transfer result received"); } OysterTransferArguments ota = new OysterTransferArguments(args.LocalFileName, args.RemoteFileName,(double)args.TotalBytes,TransferProgress,TotalFileSize,TotalTransferProgress, e,args.TransferedPercentage,(int)TotalDownloadPercentage,TR); if(On_Upload_Complete != null) On_Upload_Complete(this,ota); } catch(Exception PostError) { string peekError = PostError.Message; OysterTransferArguments Eota = new OysterTransferArguments(args); if(On_Upload_Complete != null) On_Upload_Complete(this,Eota); } #endregion Msg("Upload complete."); TransferProgress = 0; //UploadingFile = false; m_ThreadTransferCompleteEvent.Set(); }
private void FtpSession_BeginPutFile(object sender, KCommon.Net.FTP.IFtpFileTransferArgs args) { #region Send Upload_Begin_Event long TotalDownloadPercentage = 0; //System.Math.DivRem((long)TotalFileSize,args.TotalBytesTransfered,out TotalDownloadPercentage); TransferDirection e = TransferDirection.Upload; if(args.TransferDirection == KCommon.Net.FTP.TransferDirection.Download) e = TransferDirection.Download; TransferResult TR = new TransferResult(); OysterTransferArguments ota = new OysterTransferArguments(args.LocalFileName, args.RemoteFileName,(double)args.TotalBytes,0,TotalFileSize,TotalTransferProgress, e,args.TransferedPercentage,(int)TotalDownloadPercentage,TR); if(On_Upload_Begin != null) On_Upload_Begin(this,ota); #endregion LTransfer = 0; Msg(args.LocalFileName + ":" + " upload started..."); Application.DoEvents(); }