Session.PutFileToDirectory Method
Uploads one file from a local directory to a remote directory.
This is a convenient alternative to Session.PutFiles, when you want to upload only one specific file to a specific remote directory, keeping its original name.
Syntax
C#
public TransferEventArgs PutFileToDirectory( string localFilePath, string remoteDirectory, bool remove = false, TransferOptions options = null )
VB.NET
Public Function PutFileToDirectory( localFilePath As String, remoteDirectory As String, Optional remove As Boolean = False, Optional options As TransferOptions = Nothing ) As TransferEventArgs
Parameters
| Name | Description |
|---|---|
| string localFilePath | Full path to the local file to upload. |
| string remoteDirectory | Full path to the remote directory to upload the file to. |
| 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
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. Also raises Session.FileTransferProgress throughout the transfer.
Contrary to Session.PutFiles:
- 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 the target directory path ends with a slash.
- The method uploads 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.