Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Net.FtpClient;
  4. using System.Net;
  5. using System.IO;
  6. namespace MyFTP
  7. {
  8. class FTPExample
  9. {
  10. private FtpClient _client;
  11.  
  12. public void MoveFiles()
  13. {
  14. using (FtpClient _client = new FtpClient())
  15. {
  16. _client.Host = "xx.xx.xx.xxx";
  17. _client.Credentials = new NetworkCredential()
  18. {
  19. UserName = "xxx",
  20. Password = "xxxx",
  21. };
  22.  
  23. foreach (var listing in _client.GetListing())
  24. {
  25. //get a pattern from database or config to filter files for this "file movement" record (how to implement?)
  26. if (listing.Type == FtpFileSystemObjectType.File && IsMatch(listing.Name))
  27. {
  28. try
  29. {
  30. byte[] currentFile = ReadMatchedFile(listing);
  31. if (currentFile.Length > 0)
  32. {
  33. File.WriteAllBytes(@"c:mytestoutputfile.txt", currentFile);
  34. }
  35. }
  36. catch (Exception e)
  37. {
  38. }
  39. }
  40. }
  41. }
  42. }
  43.  
  44. private bool IsMatch(string fileName)
  45. {
  46. //not implemented.
  47.  
  48. return true;
  49. }
  50. private byte[] ReadMatchedFile(FtpListItem file)
  51. {
  52. byte[] buffer = new byte[file.Size];
  53.  
  54. //read data into buffer (not implemented)
  55.  
  56. return buffer;
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement