Ftp Object : MPut Method |
Visual Basic |
---|
Public Sub MPut( _ Optional ByVal Source As String = "", _ Optional ByVal Destination As String = "", _ Optional ByVal FilesTransferred As Variant, _ Optional ByVal FileErrors As Variant _ ) |
Use this method to store multiple files based on wildcards, file lists, or entire branches of a directory tree.
The following table shows some examples of wildcards:
Wildcard | Meaning |
* | Store all files in the directory and the subdirectories. |
*.* | Store all files in the directory that contain a "." in the filename. |
*.txt | Store all files in the directory with filenames that end with ".txt". |
Test* | Store all files in the directory with filenames that begin with "Test" |
*Test* | Store all files in the directory that contain "Test" in the filename. |
You may use a mixture of filenames and wildcards for Source. Filenames and wildcards may contain full paths, such as C:\Test\test.txt or C:\Test\*.txt. When Source is * then all subdirectories that do not exist on the server will be created. The entire directory tree structure will be created and stored. Any existing files will be replaced unless file permissions do not allow. 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, only one file will be transferred. Timeout has to be manually set to > 0 prior to calling Mput in order for the method to work properly. 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 'Store all files in the current directory to the current server directory Ftp1.MPut 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 'Store all files from the current directory that end with .txt ' and put them in a server directory called ~/TextFiles Ftp1.MPut "*.txt", "~/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 ' Store the entire Test directory, subdirectories included, ' on the server and put it in the ~/NewFolder directory Ftp1.MPut "C:\Test\*", "~/NewFolder" 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 Dim FilesTransferred As New DartStrings Dim FileErrors As New DartStrings Ftp1.Login "myserver", "myusername", "mypass" ' Mput files, FilesTransferred will be filled with files that have been successfully ' PUT, FileErrors will be filled with errors and their corresponding files Ftp1.MPut "C:\temp\mput\*", "", (FilesTransferred), (FileErrors) Ftp1.Logout ' Check for successfully PUT files If FilesTransferred.Count > 0 Then Debug.Print "The following files have been transferred successfully" For i = 1 To FilesTransferred.Count Debug.Print FilesTransferred(i) Next End If ' Check for errors If FileErrors.Count > 0 Then Debug.Print "The following errors were reported on the following files" For i = 1 To FileErrors.Count Debug.Print FileErrors(i) Next Else Debug.Print "No errors reported" End If MsgBox ("Done") Exit Sub onError: MsgBox (Err.Description) End Sub
<% On Error Resume Next set FilesTransferred = Server.CreateObject("Dart.DartStrings.1") set FileErrors = Server.CreateObject("Dart.DartStrings.1") Ftp1.Login "myserver", "myusername", "mypass" ' Mput files, FilesTransferred will be filled with files that have been successfully ' PUT, FileErrors will be filled with errors and their corresponding files Ftp1.MPut "C:\temp\mput\*", "", FilesTransferred, FileErrors Ftp1.Logout ' Check for successfully PUT files If FilesTransferred.Count > 0 Then Response.Write "The following files have been transferred successfully<br>" For i = 1 To FilesTransferred.Count Response.Write FilesTransferred(i) & "<br>" Next End If ' Check for errors If FileErrors.Count > 0 Then Response.Write "The following errors were reported on the following files<br>" For i = 1 To FileErrors.Count Response.Write FileErrors(i) & "<br>" Next Else Response.Write "No errors reported" End If if err = 0 then Response.Write "MPUT complete" else Response.Write err.description end if %>