Ftp Object : MGet Method |
Visual Basic |
---|
Public Sub MGet( _ Optional ByVal Source As String = "", _ Optional ByVal Destination As String = "", _ Optional ByVal FilesTransferred As Variant, _ Optional ByVal FileErrors As Variant _ ) |
Use this method to retrieve multiple files based on wildcards, file lists, or entire branches of a directory tree.
The following table shows some examples of wildcards:
Wildcard | Meaning |
* | Get all files in the directory and the subdirectories. |
*.* | Get all files in the directory that contain a "." in the filename. |
*.txt | Get all files in the directory with filenames that end with ".txt". |
Test* | Get all files in the directory with filenames that begin with "Test" |
*Test* | Get all files in the directory that contain "Test" in the filename. |
Warning Using wildcards may cause unexpected results. For example, getting ~/* is not the same as getting /*. Some systems may return different directory listings.
You may use a mixture of filenames and wildcards for Source. Filenames and wildcards may contain full paths, such as /Test/test.txt or /Test/*.txt. When Source is * then all subdirectories that do not exist on the local system will be created. The entire directory tree structure will be created and retrieved. Any existing files will be replaced unless file permissions do not allow, unless Overwrite is set to false. If a file in the file list specified by Source does not exist then the file and the corresponding error, separated by a space, is added to FileErrors and operation will continue on to the next file. Any file with a space in its name is wrapped with quotes ("). The following examples illustrate enclosing within quotes any path containing a space:
If Timeout is 0 before this method is called then the default value of 30 seconds will be used. If Timeout is greater than 0 then the value of Timeout will be used. A ptTimeout error will occur if no activity is received from the server within the timeout period.
If Destination is not a directory or does not exist then a ptInvalidParam2 error will occur.
The type specified by the Type property will be used to transfer all the files.
new:
total 12
-rw-r--r-- 1 test users 46 Jan 16 15:53 index.txt
drwxr-xr-x 2 test users 4096 Jan 16 17:27 mslfiles/
-rw-r--r-- 1 test users 46 May 1 13:15 readme.txt
This method may generate the following error code (refer to ErrorConstants for a complete list of error codes):
Private Sub Command1_Click() On Error Goto OnError ' use intrinsic error handling 'Retrieve all files in the current server directory to the 'current local directory. Ftp1.MGet Exit Sub OnError: ' Any error jumps here Debug.Print "Error #" + CStr(Err.Number) + ": " + Err.Description End Sub
Private Sub Command1_Click() On Error Goto OnError ' use intrinsic error handling 'Get all files, from the current server directory, 'that end with .txt and put them in a local directory 'called C:\TextFiles Ftp1.MGet "*.txt", "C:\TextFiles" Exit Sub OnError: ' Any error jumps here Debug.Print "Error #" + CStr(Err.Number) + ": " + Err.Description End Sub
Private Sub Command1_Click() On Error Goto OnError ' use intrinsic error handling ' Get the entire Test directory, subdirectories included, ' from the server and put it in the C:\NewFolder directory. Ftp1.MGet "Test/*", "C:\NewFolder" Exit Sub OnError: ' Any error jumps here Debug.Print "Error #" + CStr(Err.Number) + ": " + Err.Description End Sub