This is the main interface class of the WinSCP assembly.
It represents a session and provides methods for manipulating remote files over SFTP, SCP or FTP session.
public sealed class Session : IDisposable
Public NotInheritable Class Session Implements IDisposable
|string AdditionalExecutableArguments||Additional command-line arguments to be passed to
|string DebugLogPath||Path to store assembly debug log to. Default
|bool DefaultConfiguration||Deprecated. Do not use. Use
|bool DisableVersionCheck||Disables test that WinSCP executables have the same product version as this assembly.1) The property has to be set before calling
|string ExecutablePath||Path to
|string ExecutableProcessUserName||If the .NET process is running in an impersonated environment, you need to provide credentials of the impersonated account, so that the
|string HomePath||Path to a remote home directory. The property can be read only after calling
|string IniFilePath||Deprecated. Do not use. Use
|string SessionLogPath||Path to store session log file to. Default
|bool Opened||Is session opened yet?
|StringCollection Output||Output of WinSCP console session. See also
|TimeSpan ReconnectTime||Sets time limit in seconds to try reconnecting broken sessions. Default is 120 seconds. Use
|int ReconnectTimeInMilliseconds||Alternative to
|TimeSpan Timeout||Maximal interval between two consecutive outputs from WinSCP console session, before
|Abort||Forcefully aborts session.|
|AddRawConfiguration||Allows setting any configuration settings using raw format as in an INI file.|
|CalculateFileChecksum||Calculates a checksum of a remote file.|
|CreateDirectory||Creates remote directory.|
|CombinePaths||Combines strings into a remote path.|
|Dispose||Closes session and disposes object.|
|EscapeFileMask||Converts special characters in file path to make it unambiguous file mask/wildcard.|
|EnumerateRemoteFiles||Recursively enumerates remote files.|
|ExecuteCommand||Executes command on the remote server.|
|FileExists||Checks for existence of remote file.|
|GetFileInfo||Retrieves information about remote file.|
|ListDirectory||Lists remote directory.|
|MoveFile||Moves remote file to another remote directory and/or renames remote file.|
|Open||Opens the session.|
|RemoveFiles||Removes remote files.|
|ScanFingerprint||Scans a fingerprint of SSH server public key or FTPS/WebDAVS TLS certificate.|
|SynchronizeDirectories||Synchronizes local directory with remote directory.|
|TranslateLocalPathToRemote||Generates a remote path equivalent of a local path, given root paths.|
|TranslateRemotePathToLocal||Generates a local path equivalent of a remote path, given root paths.|
|Failed||Occurs on error during any operation.|
|FileTransferProgress||Occurs regularly during file transfer to report transfer progress.|
|FileTransferred||Occurs when file is transferred.|
|OutputDataReceived||Occurs on output from WinSCP console session.|
To use the class:
SessionOptionsand fill in all needed information to connect and authenticate the session automatically;
Sessioncan be left with their default values;
Openmethod passing instance of
The class is locked against concurrent accesses from multiple threads. Though you can use several instances of the class in parallel, even from different threads.
Methods from both classes throw
SessionLocalException on error in communication with WinSCP console session.
Methods for atomic operations throw
SessionRemoteException on error originating from WinSCP console session (referred to as “failure” below).
Methods for batch operations returns an instance of descendant of
OperationResultBase class (such as
SynchronizationResult). Such result class stores list of operations performed (e.g.
TransferOperationResult.Uploads), and list of failures (
Every structure representing operation performed may refer (e.g. in
TransferEventArgs.Error) to one of the failures, if the failure can be explicitly associated with the operation. So often the same failure (represented by
SessionRemoteException) will be referenced twice in the results.
But there can be failures that cannot be explicitly associated with any operation represented in results. An example is an error when listing contents of remote directory to determine list of files to downloads. The listing is not represented in the results, so the failure will be included only in a generic list of failures.
If you do not want to check the list of failures after every batch operation method call, you can use method
OperationResultBase.Check to throw the first failure in the list, if any failure occurred:
// Throw, if upload fails session.PutFiles(localPath, remotePath).Check();
Also for all failures the
Session.Failed event is raised.
The batch operation though typically aborts on the first major failure. See example on implementing recursive directory tree download with custom error handling to learn how to continue on errors.
For example how to check and print errors, but continue, see real-life example Search recursively for text in remote directory / Grep files over SFTP/FTP protocol.
Site design by Black Gate