c# - Download the latest file from an FTP server -


i have download latest file ftp server. know how download latest file computer, don't how download ftp server.

how can download latest file ftp server?

this program download latest file computer

public form1()     {         initializecomponent();          string startfolder = @"c:\users\user3\desktop\documentos xml";          system.io.directoryinfo dir = new system.io.directoryinfo(startfolder);          ienumerable<system.io.fileinfo> filelist = dir.getfiles("*.*", system.io.searchoption.alldirectories);          ienumerable<system.io.fileinfo> filequerry =             file in filelist             file.extension == ".txt"             orderby file.creationtimeutc             select file;          foreach (system.io.fileinfo fi in filequerry)             {                 var newestfile =                 (from file in filequerry                  orderby file.creationtimeutc                  select new { file.fullname, file.name })                  .first();                 textbox2.text = newestfile.fullname;             }     } 

ok, code know date of last file, how know name of file????????

you have retrieve timestamps of remote files select latest one.

modification timestamp of files in directory using features offered .net framework, not support ftp mlsd. mlsd command provides listing of remote directory in standardized machine-readable format. command , format standardized rfc 3659.

alternatives can use, supported .net framework:


alternatively can use 3rd party ftp client implementation supports modern mlsd command.

for example winscp .net assembly supports that.

there's example specific task: downloading recent file.
example powershell , sftp, translates c# , ftp easily:

// setup session options sessionoptions sessionoptions = new sessionoptions {     protocol = protocol.ftp,     hostname = "example.com",     username = "username",     password = "password", };  using (session session = new session()) {     // connect     session.open(sessionoptions);      // list of files in directory     string remotepath = "/remote/path/";     remotedirectoryinfo directoryinfo = session.listdirectory(remotepath);      // select recent file     remotefileinfo latest =         directoryinfo.files             .orderbydescending(file => file.lastwritetime)             .first();      // download selected file     localpath = @"c:\local\path\";     session.getfiles(session.escapefilemask(remotepath + latest.name), localpath).check(); } 

(i'm author of winscp)


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -