This is an old revision of the document!
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 remote 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.
Contrary to Session.PutFiles
:
- 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 uploading).
- You do not need to make sure that the target directory path ends with a slash.
- The method upload 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
.