private IEnumerable <string> getFileNamesRecursively(string folder) { FTPdirectory folders = null; try { folders = client.ListDirectoryDetail(folder); } catch (WebException ex) { //550 errors are likely. //TODO: Log error. return(new List <string>()); } List <string> files = new List <string>(); foreach (var file in folders.GetFiles()) { files.Add(file.FullName); } foreach (var dir in folders.GetDirectories()) { files = files.Concat(getFileNamesRecursively(dir.FullName)).ToList(); } return(files); }
public FTPdirectory GetFtpFiles(Uri Host, string ext = "") { FTPclient ftp = new FTPclient(Host.AbsoluteUri, FtpUser, FtpPassword); ftp.UsePassive = true; FTPdirectory ftpDir = ftp.ListDirectoryDetail(); return(ftpDir.GetFiles("")); }
private void AddFileData(string path) { const int MaxTries = 3; FTPdirectory ftpDir = new FTPdirectory(); // If the path is //. or //.. don't store it if (path.EndsWith(".")) { return; } // Looks like we're getting some random timeout failures. Putting in this loop // so we'll retry a couple times before giving up. for (int numTries = 0; numTries < MaxTries; numTries++) { try { // Get all the files and directories in this directory ftpDir = ftpClient.ListDirectoryDetail(path); // If we didn't get an exception, get out of this loop break; } catch (WebException exc) { // If we've tried a lot already, give up if (numTries >= MaxTries - 1) { throw exc; } else { // Wait a little while and try again. Thread.Sleep(1000); } } } // Store each of the files in this directory ftpDir.GetFiles("").ForEach(new Action<FTPfileInfo>(StoreFiles)); // Recursively call this function on ftpDir.GetDirectories().ForEach(new Action<FTPfileInfo>(AddFileData)); }