PageRenderTime 159ms CodeModel.GetById 4ms RepoModel.GetById 7ms app.codeStats 0ms

/Visual Studio 2008/CSFTPDownload/Readme.txt

#
Plain Text | 135 lines | 90 code | 45 blank | 0 comment | 0 complexity | be5d500aed06ca3a7370d24c77abe100 MD5 | raw file
  1. ================================================================================
  2. Windows APPLICATION: CSFTPDownload Overview
  3. ===============================================================================
  4. /////////////////////////////////////////////////////////////////////////////
  5. Summary:
  6. The sample demonstrates how to list subdirectories and files of a folder on a FTP
  7. server and download all of them.
  8. The operations includes
  9. 1. List subdirectories and files of a folder on the FTP server.
  10. When set the Method property of an FtpWebRequest to
  11. WebRequestMethods.Ftp.ListDirectoryDetails(the FTP LIST protocol method to get a
  12. detailed listing of the files on an FTP server), the response of server will
  13. contain many records of information, and each record represents a file or a directory.
  14. Depended on the FTP Directory Listing Style of the server, the record is like
  15. 1. MSDOS
  16. 1.1. Directory
  17. 12-13-10 12:41PM <DIR> Folder A
  18. 1.2. File
  19. 12-13-10 12:41PM [Size] File B
  20. NOTE: The date segment is like "12-13-10" instead of "12-13-2010" if Four-digit
  21. years is not checked in IIS or other FTP servers..
  22. 2. UNIX
  23. 2.1. Directory
  24. drwxrwxrwx 1 owner group 0 Dec 1 12:00 Folder A
  25. 2.2. File
  26. -rwxrwxrwx 1 owner group [Size] Dec 1 12:00 File B
  27. NOTE: The date segment does not contain year.
  28. 2. Download a file on the FTP server.
  29. To download a file, create a FtpWebRequest and set the Method property to
  30. WebRequestMethods.Ftp.DownloadFile.
  31. ////////////////////////////////////////////////////////////////////////////////
  32. Demo:
  33. Step1. Build this sample in VS2008.
  34. Step2. Run CSFTPDownload.exe.
  35. Step3. Type the url of a valid FTP server in the FTPServer textbox. The url should start
  36. with ftp:// like ftp://localhost
  37. * List subdirectories and files
  38. Step4. Press the button "Connect".The application will show a dialog to input the
  39. credentials. If the FTP server supports anonymous users, you can check
  40. "Log on anonymously".
  41. It may take several seconds to connect to the FTP server for the first time, then
  42. you will see the files and subdirectories in the FTP File Explorer. The items in
  43. the list box are like
  44. 2010-12-1 12:00 <DIR> Folder A
  45. 2010-12-1 12:00 1024 File B
  46. <DIR> means a folder.
  47. Step5. Double click an item contains <DIR> in the FTP File Explorer, the FTP File Explorer
  48. will navigate to this sub directory and list the files and subdirectories of it.
  49. Step6. Click the button Parent Folder, if current path is not the root path of the server,
  50. the FTP File Explorer will navigate to this parent directory and list the files and
  51. subdirectories of it.
  52. * Download files from the FTP server.
  53. Step7. Select one or more items in the FTP File Explorer , click the button Browse to
  54. choose the download path, then click the button Download.
  55. This application will download the selected items to the download path. If the selected
  56. items contains a folder, this application will also download the files and subdirectories
  57. of it.
  58. /////////////////////////////////////////////////////////////////////////////
  59. Code Logic:
  60. 1. Design a class FTPClientManager. This class supplies following features.
  61. 1.1 Check whether the Url to navigate is valid.
  62. Create a FtpWebRequest of the Url and set the Method property to
  63. WebRequestMethods.Ftp.PrintWorkingDirectory. If there is no exception, then the Url
  64. is valid.
  65. 1.2 List files and sub directories of a folder on the FTP server.
  66. Create a FtpWebRequest of the Url and set the Method property to
  67. WebRequestMethods.Ftp. ListDirectoryDetails. The response of server will contain many
  68. records of information, and each record represents a file or a directory.
  69. 1.3 Manage the FTPDownloadClient to download files.
  70. 1.4 Supply the events UrlChanged, ErrorOccurred, StatusChanged, FileDownloadCompleted
  71. NewMessageArrived.
  72. 2. Design a class FTPDownloadClient to download files from FTP server.
  73. When the download starts, it will download the file in a background thread. The downloaded
  74. data is stored in a MemoryStream first, and then written to local file.
  75. 3. Design the classes ErrorEventArgs, FileDownloadCompletedEventArgs, NewMessageEventArg
  76. and FTPClientManagerStatus used by the class FTPClientManager.
  77. 4. Design a class FTPFileSystem that represents a file on the remote FTP server. It also
  78. contains static methods to parse the response of a ListDirectoryDetails FtpWebRequest.
  79. 5. In the MainForm, register the UrlChanged event of an FTPClientManager, if the Url changed,
  80. list files and sub directories of the new url in the FTP File Explorer.
  81. It also registers the other events of FTPClientManager and log the events.
  82. /////////////////////////////////////////////////////////////////////////////
  83. References:
  84. FtpWebRequest Class
  85. http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
  86. WebRequestMethods.FTP Class
  87. http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx
  88. Unix File Permissions
  89. http://www.unix.com/tips-tutorials/19060-unix-file-permissions.html
  90. /////////////////////////////////////////////////////////////////////////////