/// <summary>Raise the <see cref="Downloaded"/> event.</summary> /// <param name="e">Event arguments.</param> protected internal void RaiseDownloaded(FTPFileTransferEventArgs e) { if (areEventsEnabled && Downloaded != null) InvokeEventHandler(Downloaded, this, e); }
/// <summary>Raise the <see cref="Uploading"/> event.</summary> /// <param name="e">Event arguments.</param> protected internal void RaiseUploading(FTPFileTransferEventArgs e) { if (areEventsEnabled && Uploading != null) InvokeEventHandler(Uploading, this, e); }
/// <summary> /// Called when a file is about to be downloaded. /// </summary> /// <param name="destStream">Stream to which data will be written.</param> /// <param name="remoteFile">Path of remote file.</param> /// <returns><c>true</c> if the operation is to continue.</returns> protected bool OnDownloading(Stream destStream, string remoteFile, long bytesDownloaded, out long remoteFileSize, out DateTime remoteModTime) { // for efficiency reasons we only initialize remoteFileSize and remoteModTime if either event is handled if (areEventsEnabled && (Downloading != null || Downloaded != null)) { remoteFileSize = GetSize(remoteFile, false); remoteModTime = GetLastWriteTime(remoteFile, false); } else { remoteFileSize = 0; remoteModTime = DateTime.MinValue; } if (areEventsEnabled && Downloading != null) { FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, destStream, remoteFile, ServerDirectory, 0, remoteFileSize, bytesDownloaded, remoteModTime, false, false, null); RaiseDownloading(e); lastTransferCancel = e.Cancel; return !e.Cancel; } else return true; }
/// <summary> /// Called when a file is about to be deleted. /// </summary> /// <param name="remoteFile">File to delete.</param> /// <returns><c>true</c> if the operation is to continue.</returns> protected bool OnDeleting(string remoteFile, out DateTime remoteModTime) { // for efficiency reasons we only initialize remoteModTime if either event is handled if (areEventsEnabled && (Downloading != null || Downloaded != null)) remoteModTime = GetLastWriteTime(remoteFile, false); else remoteModTime = DateTime.MinValue; if (areEventsEnabled && Deleting != null) { long remoteFileSize = GetSize(remoteFile, false); FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, remoteFile, ServerDirectory, 0, remoteFileSize, -1, remoteModTime, false, false, null); RaiseDeleting(e); return !e.Cancel; } else return true; }
/// <summary> /// Called when a stream is about to be uploaded. /// </summary> /// <param name="srcStream">Stream to upload.</param> /// <param name="remoteFile">Path of remote file.</param> /// <param name="append">Flag indicating whether or not the remote file is being appended to.</param> /// <returns><c>true</c> if the operation is to continue.</returns> protected bool OnUploading(Stream srcStream, ref string remoteFile, ref bool append, out long localFileSize) { // in order to avoid unnecessary log-warnings we only initialize // localFileSize and localModTime if either event is handled if (areEventsEnabled && (Uploading != null || Uploaded != null)) { try { localFileSize = srcStream.Length; } catch (Exception ex) { log.Warn("Could not get size of stream prior to upload", ex); localFileSize = -1; } } else { localFileSize = 0; } if (areEventsEnabled && Uploading != null) { long remoteFileSize = GetSize(remoteFile, false); DateTime remoteModTime = GetLastWriteTime(remoteFile, false); FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, srcStream, remoteFile, ServerDirectory, localFileSize, remoteFileSize, 0, remoteModTime, append, false, null); RaiseUploading(e); remoteFile = e.RemoteFile; append = e.Append; lastTransferCancel = e.Cancel; return !e.Cancel; } else return true; }
/// <summary> /// Called when a byte-array is about to be uploaded. /// </summary> /// <param name="bytes">Byte-array to upload.</param> /// <param name="remoteFile">Path of remote file.</param> /// <param name="append">Flag indicating whether or not the remote file is being appended to.</param> /// <returns><c>true</c> if the operation is to continue.</returns> protected bool OnUploading(byte[] bytes, ref string remoteFile, ref bool append) { if (areEventsEnabled && Uploading != null) { long len = bytes.LongLength; long remoteFileSize = GetSize(remoteFile, false); DateTime remoteModTime = GetLastWriteTime(remoteFile, false); FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, remoteFile, ServerDirectory, len, remoteFileSize, 0, remoteModTime, append, false, null); RaiseUploading(e); remoteFile = e.RemoteFile; append = e.Append; lastTransferCancel = e.Cancel; return !e.Cancel; } else return true; }
void ftp_Downloading(object sender, FTPFileTransferEventArgs e) { }
/// <summary> /// Called when a file is about to be uploaded. /// </summary> /// <param name="localPath">Path of local file.</param> /// <param name="remoteFile">Path of remote file.</param> /// <param name="append">Flag indicating whether or not the remote file is being appended to.</param> /// <returns><c>true</c> if the operation is to continue.</returns> protected bool OnUploading(string localPath, ref string remoteFile, ref bool append, ref bool resume) { if (areEventsEnabled && Uploading != null) { long localFileSize = GetLocalFileSize(localPath); long remoteFileSize = GetSize(remoteFile, false); DateTime remoteModTime = GetLastWriteTime(remoteFile, false); FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, localPath, remoteFile, ServerDirectory, localFileSize, remoteFileSize, 0, remoteModTime, append, resume, false, null); RaiseUploading(e); remoteFile = e.RemoteFile; append = e.Append; resume = e.Resume; lastTransferCancel = e.Cancel; return !e.Cancel; } else return true; }
protected internal void RaiseUploaded(FTPFileTransferEventArgs e) { if (this.areEventsEnabled && (this.Uploaded != null)) { this.InvokeEventHandler(this.Uploaded, this, e); } }
void ftp_Downloaded(object sender, FTPFileTransferEventArgs e) { pbarCurrent.Value = 100; //e.RemoteFileSize int totalProgress = (int)(e.RemoteFileSize * 100 / TotalDownloadSize); pbarTotal.Value += totalProgress; lblTotalProgress.Text = "Total Percent Completed: " + pbarTotal.Value + "%"; //pbarTotal.Value++; }
protected internal void RaiseDownloading(FTPFileTransferEventArgs e) { if (this.areEventsEnabled && (this.Downloading != null)) { this.InvokeEventHandler(this.Downloading, this, e); } }
protected bool OnUploading(string localPath, ref string remoteFile, bool append) { if (!this.areEventsEnabled || (this.Uploading == null)) { return true; } long fileSize = 0L; try { fileSize = new FileInfo(localPath).Length; } catch (Exception exception) { string message = "Failed to open file '" + localPath + "'"; this.log.Error(message, exception); throw new FTPException(message); } FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, localPath, remoteFile, this.ServerDirectory, fileSize, append, false, null); this.RaiseUploading(e); remoteFile = e.RemoteFile; this.lastTransferCancel = e.Cancel; return !e.Cancel; }
protected bool OnUploading(Stream srcStream, ref string remoteFile, bool append) { if (this.areEventsEnabled && (this.Uploading != null)) { FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, srcStream, remoteFile, this.ServerDirectory, srcStream.Length, append, false, null); this.RaiseUploading(e); remoteFile = e.RemoteFile; this.lastTransferCancel = e.Cancel; return !e.Cancel; } return true; }
protected bool OnDownloading(ref string localPath, string remoteFile) { if (this.areEventsEnabled && ((this.Downloading != null) || (this.Downloaded != null))) { this.currentFileSize = this.GetSize(remoteFile, false); } if (this.areEventsEnabled && (this.Downloading != null)) { FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, localPath, remoteFile, this.ServerDirectory, this.currentFileSize, false, false, null); this.RaiseDownloading(e); localPath = e.LocalPath; this.lastTransferCancel = e.Cancel; return !e.Cancel; } return true; }
protected bool OnDeleting(string remoteFile) { if (this.areEventsEnabled && (this.Deleting != null)) { FTPFileTransferEventArgs e = new FTPFileTransferEventArgs(true, remoteFile, this.ServerDirectory, -1L, false, false, null); this.RaiseDeleting(e); return !e.Cancel; } return true; }