Session.PutFiles Method

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

You can have WinSCP generate a code template for Session.PutFiles for you.


public TransferOperationResult PutFiles(
    string localPath,
    string remotePath,
    bool remove = false,
    TransferOptions options = null
Public Function PutFiles( _
    ByVal localPath As String, _
    ByVal remotePath As String, _
    ByVal Optional remove As Boolean = False, _
    ByVal Optional options As TransferOptions = Nothing _
) As TransferOperationResult


Name Description
string localPath Full path to local file or directory to upload. Filename in the path can be replaced with Windows wildcard1) to select multiple files. To upload all files in a directory, use mask *.
string remotePath Full path to upload the file to. When uploading multiple files, the filename in the path should be replaced with operation mask or omitted (path ends with slash).
bool remove When set to true, deletes source local file(s) after 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.

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.


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.
  library_session_putfiles.txt · Last modified: by martin

Search Documentation

This page


About donations

$9   $19   $49   $99

About donations



Site design by Black Gate