Click here to Skip to main content
15,916,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am looking to download a file from ftp server that is last modified, or we can say latest added file from server.

Please help as i am able to get file list from server but not the new one.

Thanks in advance.
-Abbas
Posted
Comments
SalouaK 29-May-13 5:58am    
Did you try to get the information of the file usinf FileInfo ?

1 solution

FileSystemWatcher fileWatcherFTP = new FileSystemWatcher();

fileWatcherFTP.Path = directoryToWatch;

fileWatcherFTP.Filter = "*.xml";

fileWatcherFTP.IncludeSubdirectories = true;

fileWatcherFTP.Created += new FileSystemEventHandler(fileWatcherFTP_Changed);

fileWatcherFTP.Changed += new FileSystemEventHandler(fileWatcherFTP_Changed);

fileWatcherFTP.EnableRaisingEvents = true;



timerFTP = new System.Timers.Timer(60000);

timerFTP.Enabled = true;

timerFTP.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);

timerFTP.Start();







void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

{

processFile ();

}




private void processFile()

{

try

{

DirectoryInfo directoryInfo = new DirectoryInfo(directoryToWatch);

FileInfo[] files = directoryInfo.GetFiles();

if (files.Count() == 0)

{

// Stop Timer when all files has been processed

timerFTP.Stop();

timerFTP.Enabled = false;

}

else

{

foreach (FileInfo fileInfo in files)

{


// process file


}

}

}

catch (Exception ex){}

}


I did not tested code. You can try this code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900