SHARE
TWEET

Untitled

a guest Jul 21st, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class FTP
  2. {
  3.     private SessionOptions opts = new SessionOptions();
  4.  
  5.     public FTP(string _userName, string _password, string _server)
  6.     {
  7.         opts.UserName = _userName;
  8.         opts.Password= _password;
  9.         opts.HostName = _server;
  10.         opts.Protocol = Protocol.Ftp;
  11.         opts.FtpMode = FtpMode.Passive;      
  12.     }        
  13.  
  14.     public string[] GetFiles(string directory)
  15.     {
  16.         try
  17.         {
  18.             using (Session session = new Session())
  19.             {
  20.                 session.Open(opts);
  21.  
  22.                 RemoteDirectoryInfo dir = session.ListDirectory(directory);
  23.                 return dir.Files.Where(x => !x.IsDirectory).Select(x => x.Name).ToArray();
  24.             }
  25.         }
  26.         catch (Exception)
  27.         {
  28.             throw;
  29.         }
  30.     }
  31. }
  32.    
  33. opts.AddRawSettings("FtpListAll", "0");
  34.    
  35. FtpListItem[] files = ftp.GetListing(path, FtpListOption.AllFiles)
  36.                 .Where(x => x.Type == FtpFileSystemObjectType.File)
  37.                 .OrderBy(x => x.Modified)
  38.                 .ToArray();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top