Session.PutFilesToDirectory Method

Uploads one or more files from local directory to remote directory.

This is a convenient alternative to Session.PutFiles, when you want to upload files to a specific remote directory, keeping their original names.


public TransferOperationResult PutFilesToDirectory(
    string localDirectory,
    string remoteDirectory,
    string filemask = null,
    bool remove = false,
    TransferOptions options = null
Public Function PutFiles(
    localDirectory As String,
    remoteDirectory As String,
    Optional filemask As Boolean = Nothing,
    Optional remove As Boolean = False,
    Optional options As TransferOptions = Nothing
) As TransferOperationResult


Name Description
string localDirectory Full path to the local directory to upload the files from.
string remoteDirectory Full path to the remote directory to upload the files to.
string filemask Windows wildcard1 to select the files or subdirectories to upload. Defaults to null to upload all files and subdirectories of the local directory.
bool remove When set to true, deletes the source local file(s) after a successful transfer. Defaults to false.
TransferOptions options Transfer options. Defaults to null, what is equivalent to new TransferOptions().

Return Value

TransferOperationResult. See also Capturing results of operations.


Exception Condition
InvalidOperationException Session is not opened.
Invalid combination of values of TransferOptions properties.
SessionLocalException Error communicating with
See the exception documentation for details.
SessionRemoteException Session has failed.
Uploading of files has failed.
See the exception documentation for details.
TimeoutException Timeout waiting for to respond.


Event Session.FileTransferred is raised for every uploaded file. Also raises Session.FileTransferProgress throughout the transfer.

The upload aborts on the first error. See the example on implementing recursive directory tree download with custom error handling. Uploads can be implemented similarly too, see an example of implementing recursive directory tree upload.

Contrary to Session.PutFiles:

  • You specify source directory path separately from an optional file mask.
  • You do not specify a target name (or an operation mask) in the destination path (original names are preserved when uploading).
  • You do not need to make sure that both directory paths end with (back)slashes.


Real-Life Examples

  1. The Windows wildcard supports * and ? only. If you want to use a full syntax of file masks, use a TransferOptions.FileMask.Back

Last modified: by martin