PageRenderTime 39ms CodeModel.GetById 29ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

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