Dart Ftp Control
MPut Method
Optional. Specifies a list of files and directories to store on the server. Wildcards are allowed, and multiple paths may be specified when separated by a space. Any path with a space must be enclosed within quotes (see Remarks below). Defaults to "".
Optional. Specifies the destination directory, on the server, to store the files. Defaults to current server directory.
Optional DartStrings Object. Filled with a list of files that were successfully stored.
Optional DartStrings Object. Filled with a list of files with corresponding errors that failed to be stored.
Description
Store (put) multiple files or entire directory trees.
Syntax
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 _
) 
Parameters
Source
Optional. Specifies a list of files and directories to store on the server. Wildcards are allowed, and multiple paths may be specified when separated by a space. Any path with a space must be enclosed within quotes (see Remarks below). Defaults to "".
Destination
Optional. Specifies the destination directory, on the server, to store the files. Defaults to current server directory.
FilesTransferred
Optional DartStrings Object. Filled with a list of files that were successfully stored.
FileErrors
Optional DartStrings Object. Filled with a list of files with corresponding errors that failed to be stored.
Remarks

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.

Notes

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

Error Codes

This method may generate the following error code (refer to ErrorConstants for a complete list of error codes):

Example
This example demonstrates storing all files in the current directory.
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
This example demonstrates storing all files based on a wildcard.
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
This example demonstrates storing an entire directory tree on the server.
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
This VB example demonstrates use of the FilesTransferred and FileErrors parameters.
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
This ASP example demonstrates use of the FilesTransferred and FileErrors parameters.
<%
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
%>
See Also

Ftp Object  | Ftp Members


PowerTCP FTP for ActiveX Documentation Version 2.2
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic