public void RemoveDirectory(string url) { string filename = FTPHelpers.GetFileName(url); if (filename == "." || filename == "..") { return; } List <FTPLineResult> files = ListDirectoryDetails(url); string path = FTPHelpers.GetDirectoryName(url); foreach (FTPLineResult file in files) { if (file.IsDirectory) { RemoveDirectory(FTPHelpers.CombineURL(url, file.Name)); } else { DeleteFile(FTPHelpers.CombineURL(url, file.Name)); } } FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url); request.Proxy = this.Options.ProxySettings; request.Method = WebRequestMethods.Ftp.RemoveDirectory; request.Credentials = new NetworkCredential(this.Options.Account.UserName, this.Options.Account.Password); request.KeepAlive = false; request.GetResponse(); WriteOutput("RemoveDirectory: " + url); }
public void UploadData(Stream stream, string remotePath) { if (Connect()) { progress = new ProgressManager(stream.Length); try { Client.PutFile(stream, remotePath, FileAction.Create); } catch (Exception e) { if (e.InnerException.Message.Contains("No such file or directory")) { MakeMultiDirectory(FTPHelpers.GetDirectoryName(remotePath)); Client.PutFile(stream, remotePath, FileAction.Create); } else { throw e; } } } }