Zoltan Kerenyi

Zoltan Kerenyi

  • NA
  • 72
  • 12.4k

Download only the new file from FTP server

Dec 1 2020 4:30 PM
Hi,
 
Im trying to devise an algorithm for a remote FTP folder, since as far as I know it is not an easy task to mount a remote ftp in windows environment and c sharp.
 
So in every 2-3 minute I would log into the FTP shared folder (qnap) and search for the latest files and folders.
An event triggering is not possible since the remote shared folder is not mounted locally. So I would maintain a file list of the previous probe, and look for the difference, and only download the diff.
 
But the first obstacle is when listing the remote directory. 1 file is a string of attributes and the file name. Do you have a solution to this sproblem?
 
Thanks,
Zolee
 
here is the code so far:
  1. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://192.168.50.100/FolderA");  
  2. request.Credentials = new NetworkCredential("user""pass");  
  3. request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;  
  4. request.KeepAlive = false;  
  5. request.UseBinary = true;  
  6. FtpWebResponse response = (FtpWebResponse)request.GetResponse();  
  7. Stream responseStream = response.GetResponseStream();  
  8. StreamReader reader = new StreamReader(responseStream);  
  9. //List<string> files = new List<string>();  
  10. List<string> files = reader.ReadToEnd().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();  
  11. reader.Close();  
  12. response.Close();  
  13. foreach (var item in files)  
  14. {  
  15. Console.WriteLine(item);  

Answers (2)