Differences

This shows you the differences between the selected revisions of the page.

library_session 2016-07-29 library_session 2023-09-08 (current)
Line 2: Line 2:
This is the main interface class of the [[library|WinSCP assembly]]. This is the main interface class of the [[library|WinSCP assembly]].
-It represents a session and provides methods for manipulating remote files over SFTP, SCP or FTP session.+It represents a session and provides methods for manipulating remote files over SFTP, FTP, WebDAV, S3 or SCP session.
~~AD~~ ~~AD~~
-===== Syntax =====+===== [[syntax]] Syntax =====
Namespace: ''WinSCP'' Namespace: ''WinSCP''
Line 22: Line 22:
| Session() | Default constructor. | | Session() | Default constructor. |
-===== Properties =====+===== [[properties]] Properties =====
^ Name ^ Description ^ ^ Name ^ Description ^
| string ==AdditionalExecutableArguments== | Additional command-line arguments to be passed to ''[[executables#winscp.com|winscp.com]]''. In general, this should be left with default ''null''. | | string ==AdditionalExecutableArguments== | Additional command-line arguments to be passed to ''[[executables#winscp.com|winscp.com]]''. In general, this should be left with default ''null''. |
 +| int ==DebugLogLevel== | Logging level of session and debug logs. The default value is ''0''. The value can be in range ''-1''...''2'' (for session log file that means //Reduced//, //Normal//, //Debug 1// and //Debug 2// logging levels respectively). |
| string ==DebugLogPath== | Path to store assembly debug log to. Default ''null'' means, no debug log file is created. See also ''[[#sessionlogpath|SessionLogPath]]''. The property has to be set before calling ''Open''. | | string ==DebugLogPath== | Path to store assembly debug log to. Default ''null'' means, no debug log file is created. See also ''[[#sessionlogpath|SessionLogPath]]''. The property has to be set before calling ''Open''. |
-| bool ==DefaultConfiguration== | Deprecated. Do not use. Use ''[[library_session_addrawconfiguration|Session.AddRawConfiguration]]'' instead. | +| <del>bool ==DefaultConfiguration==</del> | Deprecated. Do not use. Use ''[[library_session_addrawconfiguration|Session.AddRawConfiguration]]'' instead. | 
-| bool ==DisableVersionCheck== | Disables test that WinSCP [[executables|executables]] have the same product version as this assembly.((Note, even if you set this property, you need to use the assembly with compatible WinSCP executable only. Otherwise the behavior is unpredictable. In general, it is not recommended to use this. In neither case will you be able to use the assembly with WinSCP 5.0.4 or older.)) The property has to be set before calling ''Open''. | +| bool ==DisableVersionCheck== | Disables test that WinSCP [[executables|executables]] have the same product version as this assembly.((Note, even if you set this property, you need to use the assembly with compatible WinSCP executable only. Otherwise the behavior is unpredictable. In general, it is not recommended to use this. In neither case will you be able to use the assembly with WinSCP 5.0.4 or older.)) The property has to be set before calling ''Open''. \\ One of few legitimate uses of the property is when [[library_install#merge|merging WinSCP .NET assembly into another assembly]]. | 
-| string ==ExecutablePath== | Path to ''[[executables#winscp.exe|winscp.exe]]''. The default is ''null'', meaning that ''winscp.exe'' is looked for in the same directory as this assembly or in an installation folder. The property has to be set before calling ''Open''. | +| string ==ExecutablePath== | Path to ''[[executables#winscp.exe|winscp.exe]]''. If not set, ''winscp.exe'' is looked for in the same directory as this assembly or in an installation folder (and the property returns the found path). The property has to be set before calling ''Open''. | 
-| string ==ExecutableProcessUserName== | If the .NET process is running in an impersonated environment, you need to provide credentials of the impersonated account, so that the ''winscp.exe'' process can be started with the same privileges. |+| string ==ExecutableProcessUserName== | If the .NET process is running in an impersonated environment, you need to provide credentials of the impersonated account, so that the ''winscp.exe'' process can be started with the same privileges. \\ Not supported in .NET Standard. |
| SecureString ==ExecutableProcessPassword== | See ''[[#executableprocessusername|ExecutableProcessUserName]]''. | | SecureString ==ExecutableProcessPassword== | See ''[[#executableprocessusername|ExecutableProcessUserName]]''. |
| string ==HomePath== | Path to a remote home directory. The property can be read only after calling ''Open''. | | string ==HomePath== | Path to a remote home directory. The property can be read only after calling ''Open''. |
-| string ==IniFilePath== | Deprecated. Do not use. Use ''[[library_session_addrawconfiguration|Session.AddRawConfiguration]]'' instead. |+| <del>string ==IniFilePath==</del> | Deprecated. Do not use. Use ''[[library_session_addrawconfiguration|Session.AddRawConfiguration]]'' instead. |
| string ==SessionLogPath== | Path to store [[logging|session log file]] to. Default ''null'' means, no session log file is created. See also ''[[#debuglogpath|DebugLogPath]]''. The property has to be set before calling ''Open''. | | string ==SessionLogPath== | Path to store [[logging|session log file]] to. Default ''null'' means, no session log file is created. See also ''[[#debuglogpath|DebugLogPath]]''. The property has to be set before calling ''Open''. |
| bool ==Opened== | Is session opened yet? ''true'', when ''Open'' was successfully called already. Read-only. | | bool ==Opened== | Is session opened yet? ''true'', when ''Open'' was successfully called already. Read-only. |
Line 38: Line 39:
| TimeSpan ==ReconnectTime== | Sets time limit in seconds to try reconnecting broken sessions. Default is 120 seconds. Use ''TimeSpan.MaxValue'' to remove any limit. The property has to be set before calling ''Open''. | | TimeSpan ==ReconnectTime== | Sets time limit in seconds to try reconnecting broken sessions. Default is 120 seconds. Use ''TimeSpan.MaxValue'' to remove any limit. The property has to be set before calling ''Open''. |
| int ==ReconnectTimeInMilliseconds== | Alternative to ''[[#reconnecttime|ReconnectTime]]''. Particularly useful for COM hosts, that cannot use ''TimeSpan'', such as Visual Basic. | | int ==ReconnectTimeInMilliseconds== | Alternative to ''[[#reconnecttime|ReconnectTime]]''. Particularly useful for COM hosts, that cannot use ''TimeSpan'', such as Visual Basic. |
-| TimeSpan ==Timeout== | Maximal interval between two consecutive outputs from WinSCP console session, before ''TimeoutException'' is thrown. The default is one minute. It's not recommended to change the value. For session/connection timeout, see ''[[library_sessionoptions#timeout|SessionOptions.Timeout]]''. |+| TimeSpan ==Timeout== | Maximal interval between two consecutive outputs from WinSCP console session, before ''TimeoutException'' is thrown. The default is one minute. It's not recommended to change the value. For session/connection timeout, see ''[[library_sessionoptions#timeout|SessionOptions.Timeout]]''. When ''SessionOptions.Timeout'' is longer, its value is used instead. | 
 +| string XmlLogPath | Path to XML log file. If not set explicitly, temporary path is generated on ''Open'' call. The property has to be changed afterwards. | 
 +| bool XmlLogPreserve | When set to ''true'', the XML log is preserved after the session closes. |
-===== Methods =====+===== [[methods]] Methods =====
^ Name ^ Description ^ ^ Name ^ Description ^
| [[library_session_abort|Abort]] | Forcefully aborts session. | | [[library_session_abort|Abort]] | Forcefully aborts session. |
| [[library_session_addrawconfiguration|AddRawConfiguration]] | Allows setting any configuration settings using raw format as in an INI file. | | [[library_session_addrawconfiguration|AddRawConfiguration]] | Allows setting any configuration settings using raw format as in an INI file. |
| [[library_session_calculatefilechecksum|CalculateFileChecksum]] | Calculates a checksum of a remote file. | | [[library_session_calculatefilechecksum|CalculateFileChecksum]] | Calculates a checksum of a remote file. |
-| [[library_session_createdirectory|CreateDirectory]] | Creates remote directory. | 
| [[library_session_close|Close]] | Closes session. | | [[library_session_close|Close]] | Closes session. |
-| [[library_session_combinepaths|CombinePaths]] | Combines strings into a remote path. |+| <del>[[library_session_combinepaths|CombinePaths]]</del> | Deprecated. Combines strings into a remote path. | 
 +| [[library_session_comparedirectories|CompareDirectories]] | Compares directories, the same way ''Session.SynchronizeDirectories'' method does, but returns differences only. | 
 +| [[library_session_createdirectory|CreateDirectory]] | Creates remote directory. |
| [[library_session_dispose|Dispose]] | Closes session and disposes object. | | [[library_session_dispose|Dispose]] | Closes session and disposes object. |
-| [[library_session_escapefilemask|EscapeFileMask]] | Converts special characters in file path to make it unambiguous file mask/wildcard. |+| [[library_session_duplicatefile|DuplicateFile]] | Duplicates remote file to another remote directory. | 
 +| <del>[[library_session_escapefilemask|EscapeFileMask]]</del> | Deprecated. Converts special characters in file path to make it unambiguous file mask/wildcard. |
| [[library_session_enumerateremotefiles|EnumerateRemoteFiles]] | Recursively enumerates remote files. | | [[library_session_enumerateremotefiles|EnumerateRemoteFiles]] | Recursively enumerates remote files. |
| [[library_session_executecommand|ExecuteCommand]] | Executes command on the remote server.  | | [[library_session_executecommand|ExecuteCommand]] | Executes command on the remote server.  |
| [[library_session_fileexists|FileExists]] | Checks for existence of remote file. | | [[library_session_fileexists|FileExists]] | Checks for existence of remote file. |
| [[library_session_getfileinfo|GetFileInfo]] | Retrieves information about remote file. | | [[library_session_getfileinfo|GetFileInfo]] | Retrieves information about remote file. |
-| [[library_session_getfiles|GetFiles]] | Downloads files. |+| [[library_session_getfile|GetFile]] | Streams remote file data. | 
 +| [[library_session_getfiles|GetFiles]] | Downloads files (optionally under a different name). | 
 +| [[library_session_getfilestodirectory|GetFilesToDirectory]] | Downloads files. | 
 +| [[library_session_getfiletodirectory|GetFileToDirectory]] | Downloads one specific file. |
| [[library_session_listdirectory|ListDirectory]] | Lists remote directory. | | [[library_session_listdirectory|ListDirectory]] | Lists remote directory. |
| [[library_session_movefile|MoveFile]] | Moves remote file to another remote directory and/or renames remote file. | | [[library_session_movefile|MoveFile]] | Moves remote file to another remote directory and/or renames remote file. |
| [[library_session_open|Open]] | Opens the session. | | [[library_session_open|Open]] | Opens the session. |
-| [[library_session_putfiles|PutFiles]] | Uploads files. |+| [[library_session_putfile|PutFile]] | Streams data to a remote file. | 
 +| [[library_session_putfiles|PutFiles]] | Uploads files (optionally under a different name). | 
 +| [[library_session_putfilestodirectory|PutFilesToDirectory]] | Uploads files. | 
 +| [[library_session_putfiletodirectory|PutFileToDirectory]] | Uploads one specific file. | 
 +| [[library_session_removefile|RemoveFile]] | Removes one specific remote file. |
| [[library_session_removefiles|RemoveFiles]] | Removes remote files. | | [[library_session_removefiles|RemoveFiles]] | Removes remote files. |
| [[library_session_scanfingerprint|ScanFingerprint]] | Scans a fingerprint of SSH server public key or FTPS/WebDAVS TLS certificate. | | [[library_session_scanfingerprint|ScanFingerprint]] | Scans a fingerprint of SSH server public key or FTPS/WebDAVS TLS certificate. |
| [[library_session_synchronizedirectories|SynchronizeDirectories]] | Synchronizes local directory with remote directory. | | [[library_session_synchronizedirectories|SynchronizeDirectories]] | Synchronizes local directory with remote directory. |
-| [[library_session_translatelocalpathtoremote|TranslateLocalPathToRemote]] | Generates a remote path equivalent of a local path, given root paths. | +| <del>[[library_session_translatelocalpathtoremote|TranslateLocalPathToRemote]]</del> | Deprecated. Generates a remote path equivalent of a local path, given root paths. | 
-| [[library_session_translateremotepathtolocal|TranslateRemotePathToLocal]] | Generates a local path equivalent of a remote path, given root paths. |+| <del>[[library_session_translateremotepathtolocal|TranslateRemotePathToLocal]]</del> | Deprecated. Generates a local path equivalent of a remote path, given root paths. | 
 +| [[library_session_trygetfileinfo|TryGetFileInfo]] | Retrieves information about remote file. |
-===== Events =====+===== [[events]] Events =====
^ Name ^ Description ^ ^ Name ^ Description ^
| [[library_session_failed|Failed]] | Occurs on error during any operation. | | [[library_session_failed|Failed]] | Occurs on error during any operation. |
Line 72: Line 85:
| [[library_session_filetransferred|FileTransferred]] | Occurs when file is transferred. | | [[library_session_filetransferred|FileTransferred]] | Occurs when file is transferred. |
| [[library_session_outputdatareceived|OutputDataReceived]] | Occurs on output from WinSCP console session.  | | [[library_session_outputdatareceived|OutputDataReceived]] | Occurs on output from WinSCP console session.  |
 +| [[library_session_queryreceived|QueryReceived]] | Occurs when a decision is needed (i.e. typically on any non-fatal error). |
-===== Remarks =====+===== [[remarks]] Remarks =====
To use the class: To use the class:
  * Create an instance of ''[[library_sessionoptions|SessionOptions]]'' and fill in all needed information to connect and authenticate the session automatically;   * Create an instance of ''[[library_sessionoptions|SessionOptions]]'' and fill in all needed information to connect and authenticate the session automatically;
Line 85: Line 99:
==== [[results]] Capturing Results of Operations ==== ==== [[results]] Capturing Results of Operations ====
-There are two classes of operations, hence two classes of methods; atomic operations, such as ''[[library_session_open|Open]]'', ''[[library_session_open|ListDirectory]]'', etc; and batch operations, such as ''[[library_session_getfiles|GetFiles]]'', ''[[library_session_putfiles|PutFiles]]'', ''[[library_session_synchronizedirectories|SynchronizeDirectories]]'', etc.+There are two classes of operations, hence two classes of methods; atomic operations, such as ''[[library_session_open|Open]]'', ''[[library_session_listdirectory|ListDirectory]]'', etc; and batch operations, such as ''[[library_session_getfiles|GetFiles]]'', ''[[library_session_putfiles|PutFiles]]'', ''[[library_session_synchronizedirectories|SynchronizeDirectories]]'', etc.
Methods from both classes throw ''[[library_sessionlocalexception|SessionLocalException]]'' on error in communication with WinSCP console session. Methods from both classes throw ''[[library_sessionlocalexception|SessionLocalException]]'' on error in communication with WinSCP console session.
Line 91: Line 105:
Methods for atomic operations throw ''[[library_sessionremoteexception|SessionRemoteException]]'' on error originating from WinSCP console session (referred to as "failure" below). Methods for atomic operations throw ''[[library_sessionremoteexception|SessionRemoteException]]'' on error originating from WinSCP console session (referred to as "failure" below).
-Methods for batch operations returns an instance of descendant of ''[[library_operationresultbase|OperationResultBase]]'' class (such as ''[[library_transferoperationresult|TransferOperationResult]]'' or ''[[library_synchronizationresult|SynchronizationResult]]''). Such result class stores list of operations performed (e.g. ''TransferOperationResult.Uploads''), and list of failures (''OperationResultBase.Failures'').+Methods for batch operations return an instance of descendant of ''[[library_operationresultbase|OperationResultBase]]'' class (such as ''[[library_transferoperationresult|TransferOperationResult]]'' or ''[[library_synchronizationresult|SynchronizationResult]]''). Such result class stores list of operations performed (e.g. ''TransferOperationResult.Uploads''), and list of failures (''OperationResultBase.Failures'').
Every structure representing operation performed may refer (e.g. in ''[[library_transfereventargs|TransferEventArgs]].Error'') to one of the failures, if the failure can be explicitly associated with the operation. So often the same failure (represented by ''[[library_sessionremoteexception|SessionRemoteException]]'') will be referenced twice in the results. Every structure representing operation performed may refer (e.g. in ''[[library_transfereventargs|TransferEventArgs]].Error'') to one of the failures, if the failure can be explicitly associated with the operation. So often the same failure (represented by ''[[library_sessionremoteexception|SessionRemoteException]]'') will be referenced twice in the results.
Line 106: Line 120:
Also for all failures the ''[[library_session_failed|Session.Failed]]'' event is raised. Also for all failures the ''[[library_session_failed|Session.Failed]]'' event is raised.
-The batch operation though typically aborts on the first major failure. See example on [[library_example_recursive_download_custom_error_handling|implementing recursive directory tree download with custom error handling]] to learn how to continue on errors.+The batch operation though typically aborts on the first major failure. To customize error processing, handle ''[[library_session_queryreceived|Session.QueryReceived]]''. //For an example, see [[library_example_recursive_download_custom_error_handling|*]].//
===== Example ===== ===== Example =====
For simple handling of errors, see [[library#example|overall example for WinSCP .NET assembly]] or [[library_examples|any other example]]. For simple handling of errors, see [[library#example|overall example for WinSCP .NET assembly]] or [[library_examples|any other example]].
-For example how to check and print errors, but continue, see real-life example [[library_example_recursive_search_text|Search recursively for text in remote directory / Grep files over SFTP/FTP protocol]].+For example how to check and print errors, but continue, see real-life example [[library_example_recursive_search_text|*]].

Last modified: by martin