Session.GetFilesToDirectory Method

Downloads one or more files from remote directory to a local directory.

This is a convenient alternative to Session.GetFiles, when you want to download files to a specific local directory, keeping their original names.


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


Name Description
string remoteDirectory Full path to the remote directory to download the files from.
string localDirectory Full path to the local directory to download the files to.
string filemask File mask to select files or subdirectories to download. Defaults to null to download all files and subdirectories of the remote directory.
bool remove When set to true, deletes source remote file(s) after a successful transfer. Defaults to false.
TransferOptions options Transfer options. Defaults to null, what is an 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.
Downloading of files has failed.
See the exception documentation for details.
TimeoutException Timeout waiting for to respond.


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

The download aborts on the first error. See how to implement recursive directory tree download with custom error handling.

Contrary to Session.GetFiles:

  • 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.


Real-Life Examples

Last modified: by martin