This is an old revision of the document!
Session.GetFileToDirectory Method
Downloads one file from a remote directory to a local directory.
This is a convenient alternative to Session.GetFiles
, when you want to download only one specific file to a specific local directory, keeping its original name.
Syntax
C#
public TransferEventArgs GetFileToDirectory( string remoteFilePath, string localDirectory, bool remove = false, TransferOptions options = null )
VB.NET
Public Function GetFilesToDirectory( remoteFilePath As String, localDirectory As String, Optional remove As Boolean = False, Optional options As TransferOptions = Nothing ) As TransferEventArgs
Parameters
Name | Description |
---|---|
string remoteFilePath | Full path to the remote file to download. |
string localDirectory | Full path to the local directory to download the file to. The directory is created, if it does not exist. |
bool remove | When set to true , deletes source remote file after a successful transfer. Defaults to false . |
TransferOptions options | Transfer options. Defaults to null , what is an equivalent to new TransferOptions() . |
Return Value
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. Downloading of files has failed. See the exception documentation for details. |
TimeoutException | Timeout waiting for winscp.com to respond. |
Remarks
Event Session.FileTransferred
is raised. Also raises Session.FileTransferProgress
throughout the transfer.
Contrary to Session.GetFiles
:
- You specify a path to the source file, not a wildcard, so you do not need to escape a literal file name.
- 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 the target directory path ends with a backslash.
- The method downloads files only. It throws when the source path points to a directory.
- The method throws an exception on error automatically. No need to call
OperationResultBase.Check
.