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.

This feature is available only in the latest beta release.

Syntax

C#
public TransferOperationResult PutFilesToDirectory(
    string localDirectory,
    string remoteDirectory,
    string filemask = null,
    bool remove = false,
    TransferOptions options = null
)
VB.NET
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

Parameters

Name Description
string localDirectory Full path to the remote directory to download the files from.
string remoteDirectory Full path to the local directory to download 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.

Exceptions

Exception Condition
InvalidOperationException Session is not opened.
ArgumentException
ArgumentOutOfRangeException
Invalid combination of values of TransferOptions properties.
SessionLocalException Error communicating with winscp.com.
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 winscp.com to respond.

Remarks

Event Session.FileTransferred is raised for every uploaded file.

The upload aborts on the first error. See 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 downloading).
  • You do not need to make sure that both directory paths end with (back)slashes.
  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