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 string GetUriPath(string fileName, bool customPath) { if (string.IsNullOrEmpty(this.Host)) { return(string.Empty); } string path = string.Empty; string host = this.Host; string lHttpHomePath = GetHttpHomePath(); string lFolderPath = GetSubFolderPath(); if (HttpHomePathNoExtension) { int index = fileName.LastIndexOf('.'); if (index > -1) { fileName = fileName.Remove(index); } } if (host.StartsWith("ftp.")) { host = host.Remove(0, 4); } if (lHttpHomePath.StartsWith("@") || customPath) { lFolderPath = string.Empty; } if (string.IsNullOrEmpty(lHttpHomePath)) { path = FTPHelpers.CombineURL(host, lFolderPath, fileName); } else { string httppath = lHttpHomePath.Replace("%host", host).TrimStart('@'); path = FTPHelpers.CombineURL(httppath, lFolderPath, fileName); } if (!path.StartsWith(BrowserProtocol.GetDescription())) { switch (BrowserProtocol) { case UploadersLib.BrowserProtocol.ServerProtocol: path = FTPHelpers.CombineURL(FTPAddress, lFolderPath, fileName); break; default: path = BrowserProtocol.GetDescription() + path; break; } } return(path); }
public string GetFtpPath(string fileName) { string ftpAddress = this.FTPAddress; if (string.IsNullOrEmpty(ftpAddress)) { return(string.Empty); } return(FTPHelpers.CombineURL(ftpAddress, this.GetSubFolderPath(), fileName)); }
public string GetLocalhostUri(string fileName) { string LocalhostAddress = this.LocalUri; if (string.IsNullOrEmpty(LocalhostAddress)) { return(string.Empty); } return(FTPHelpers.CombineURL(LocalhostAddress, this.GetSubFolderPath(), fileName)); }
public void MakeMultiDirectory(string dirName) { string path = ""; string[] dirs = dirName.Split('/'); foreach (string dir in dirs) { if (!string.IsNullOrEmpty(dir)) { path = FTPHelpers.CombineURL(path, dir); MakeDirectory(FTPHelpers.CombineURL(Options.Account.FTPAddress, path)); } } WriteOutput("MakeMultiDirectory: " + dirName); }
public string GetUriPath(string fileName, bool customPath) { if (string.IsNullOrEmpty(this.LocalhostRoot)) { return(string.Empty); } fileName = HttpUtility.UrlEncode(fileName).Replace("+", "%20"); string path = string.Empty; string httppath = string.Empty; string lHttpHomePath = GetHttpHomePath(); if (string.IsNullOrEmpty(lHttpHomePath)) { RemoteProtocol = BrowserProtocol.File; } else if (!string.IsNullOrEmpty(lHttpHomePath) && RemoteProtocol == BrowserProtocol.File) { RemoteProtocol = BrowserProtocol.Http; } string lFolderPath = this.GetSubFolderPath(); if (lHttpHomePath.StartsWith("@") || customPath) { lFolderPath = string.Empty; } if (string.IsNullOrEmpty(lHttpHomePath)) { httppath = LocalUri.Replace("file://", ""); } else { httppath = lHttpHomePath.Replace("%host", this.LocalhostRoot).TrimStart('@'); } path = FTPHelpers.CombineURL(this.Port == 80 ? httppath : string.Format("{0}:{1}", httppath, this.Port), lFolderPath, fileName); if (!path.StartsWith(RemoteProtocol.GetDescription())) { path = RemoteProtocol.GetDescription() + path; } return(path); }
public void UploadFiles(string[] localPaths, string remotePath) { foreach (string file in localPaths) { if (!string.IsNullOrEmpty(file)) { string filename = Path.GetFileName(file); if (File.Exists(file)) { UploadFile(file, FTPHelpers.CombineURL(remotePath, filename)); } else if (Directory.Exists(file)) { List <string> filesList = new List <string>(); filesList.AddRange(Directory.GetFiles(file)); filesList.AddRange(Directory.GetDirectories(file)); string path = FTPHelpers.CombineURL(remotePath, filename); MakeDirectory(path); UploadFiles(filesList.ToArray(), path); } } } }