public void UploadFileAsync(string LocalFullPath, string RemoteFileName, bool OverWriteRemoteFile) { try { if (!((this.IsValidFileChars(RemoteFileName) && this.IsValidFileChars(Path.GetFileName(LocalFullPath))) && this.IsValidPathChars(Path.GetDirectoryName(LocalFullPath)))) { throw new Exception("非法文件名或目录名!"); } if (!(OverWriteRemoteFile || !this.FileExist(RemoteFileName))) { throw new Exception("FTP服务上面已经存在同名文件!"); } if (!System.IO.File.Exists(LocalFullPath)) { throw new Exception("本地文件不存在!"); } FTPWebClient class2 = new FTPWebClient(); class2.UploadProgressChanged += new UploadProgressChangedEventHandler(this.method_5); class2.UploadFileCompleted += new UploadFileCompletedEventHandler(this.method_4); class2.Credentials = new NetworkCredential(this.UserName, this.Password); if (this.Proxy != null) { class2.Proxy = this.Proxy; } class2.UploadFileAsync(new System.Uri(this.Uri.ToString() + RemoteFileName), LocalFullPath); } catch (Exception exception) { this.ErrorMsg = exception.ToString(); throw exception; } }
public void DownloadFileAsync(string RemoteFileName, string LocalFullPath) { try { if (!this.IsValidFileChars(RemoteFileName)) { throw new Exception("非法文件名或目录名!"); } if (System.IO.File.Exists(LocalFullPath)) { throw new Exception("当前路径下已经存在同名文件!"); } FTPWebClient class2 = new FTPWebClient(); class2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(this.method_3); class2.DownloadFileCompleted += new AsyncCompletedEventHandler(this.method_2); class2.Credentials = new NetworkCredential(this.UserName, this.Password); if (this.Proxy != null) { class2.Proxy = this.Proxy; } class2.DownloadFileAsync(new System.Uri(this.Uri.ToString() + RemoteFileName), LocalFullPath); } catch (Exception exception) { this.ErrorMsg = exception.ToString(); throw exception; } }