//Gets the file last modified date and size for change comparison /* * public WebFileInfo GetUrlInfo(string URL) * { * WebFileInfo result = null; * * using (FtpClient webInfo = new FtpClient("ftp://www.url.com")) * { * webInfo.Credentials = new NetworkCredential("u_name", "pw"); * webInfo.Host = "ftp://www.url.com"; * webInfo.Connect(); * webInfo.GetObjectInfo(URL); * * result = new WebFileInfo() * { * URL = URL, * ModifiedDate = webInfo.GetModifiedTime(URL), * Length = webInfo.GetFileSize(URL), * }; * } * return result; * } */ public List <WebFileInfo> GetFilesFromDirectoryListing(string URL) { //gets the list of file names on the server List <WebFileInfo> result = new List <WebFileInfo>(); var streamToLines = new List <string>(); using (FtpClient conn = new FtpClient(URL)) { conn.Credentials = new NetworkCredential("85th_user", "85th_user"); //Seems to not be needed at this stage. //conn.EncryptionMode = FtpEncryptionMode.Implicit; //conn.SslProtocols = SslProtocols.Tls; //conn.SocketKeepAlive = true; //conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate); conn.Connect(); //void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) //{ // add logic to test if certificate is valid here // e.Accept = true; //} conn.SetWorkingDirectory(FTP_WORKING_DIRECTORY); var list = conn.GetListing( conn.GetWorkingDirectory(), //FtpListOption.Modify | FtpListOption.Size | FtpListOption.DerefLinks | FtpListOption.Recursive | FtpListOption.ForceList); //FtpListOption.Size | FtpListOption.DerefLinks | FtpListOption.Recursive | FtpListOption.ForceList); //FtpListOption.DerefLinks | FtpListOption.Recursive | FtpListOption.ForceList); FtpListOption.Recursive | FtpListOption.DerefLinks | FtpListOption.ForceList); foreach (FtpListItem item in list) { switch (item.Type) { case FtpFileSystemObjectType.Directory: break; case FtpFileSystemObjectType.File: var newWebFileInfo = new WebFileInfo() { URL = item.FullName, Length = item.Size, ModifiedDate = item.Modified }; result.Add(newWebFileInfo); break; case FtpFileSystemObjectType.Link: if (item.LinkObject != null) { // switch (item.LinkObject.Type)... } break; } } return(result); } }
public FilePair(WebFileInfo remoteFileInfo, string localFilename) { RemoteFileInfo = remoteFileInfo; LocalFilename = localFilename.Replace('/', Path.DirectorySeparatorChar); }