Differences

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

library_from_script 2016-02-04 library_from_script 2022-06-16 (current)
Line 5: Line 5:
Start by choosing a language. WinSCP .NET assembly can be used from any .NET language or any language that supports COM. Start by choosing a language. WinSCP .NET assembly can be used from any .NET language or any language that supports COM.
-If you do not have your own preferred language, use [[library_powershell|Windows PowerShell]].+If you do not have your own preferred language, use [[library_powershell|PowerShell]].
===== Mapping Script Commands to .NET Assembly Calls ===== ===== Mapping Script Commands to .NET Assembly Calls =====
Line 16: Line 16:
To emulate the ''option batch abort'' call a method ''[[library_operationresultbase|OperationResultBase]].Check'' for all ''Session'' methods that return an operation result (such as ''[[library_session_getfiles|GetFiles]]'', ''[[library_session_putfiles|PutFiles]]'', and ''[[library_session_synchronizedirectories|SynchronizeDirectories]]''). To emulate the ''option batch abort'' call a method ''[[library_operationresultbase|OperationResultBase]].Check'' for all ''Session'' methods that return an operation result (such as ''[[library_session_getfiles|GetFiles]]'', ''[[library_session_putfiles|PutFiles]]'', and ''[[library_session_synchronizedirectories|SynchronizeDirectories]]'').
 +
 +If you are using ''option batch continue'' mode, handle ''[[library_session_queryreceived|Session.QueryReceived]]'' event and call ''[[ library_queryreceivedeventargs#continue|QueryReceivedEventArgs.Continue]]'' in the handler. //For an example, see [[library_example_recursive_download_custom_error_handling|*]].//
Read more about [[library_session#results|capturing errors]] in .NET assembly. Documentation for converting an individual scripting commands (such as ''get'' [[scriptcommand_get#net|command mapping]]) details more mapping specifics for the respective operations. Read more about [[library_session#results|capturing errors]] in .NET assembly. Documentation for converting an individual scripting commands (such as ''get'' [[scriptcommand_get#net|command mapping]]) details more mapping specifics for the respective operations.
==== [[default_config]] Default Configuration ==== ==== [[default_config]] Default Configuration ====
-Scripting mode by default [[scripting#configuration|shares configuration]] with graphical mode. On the contrary the .NET assembly is by default isolated from graphical mode configuration (equivalent to using ''[[commandline#configuration|/ini=nul]]'' command-line parameter in scripting mode).+Scripting mode by default [[scripting#configuration|shares configuration]] with graphical mode. On the contrary the .NET assembly is isolated from graphical mode configuration (equivalent to using ''[[commandline#configuration|/ini=nul]]'' command-line parameter in scripting mode).
It means that you cannot use [[session_configuration#site|stored sites]], when opening session with .NET assembly. You need to configure all your site settings directly in your code (using ''[[library_sessionoptions|SessionOptions]]'' class). It means that you cannot use [[session_configuration#site|stored sites]], when opening session with .NET assembly. You need to configure all your site settings directly in your code (using ''[[library_sessionoptions|SessionOptions]]'' class).
Line 51: Line 53:
<code winscp> <code winscp>
# Connect # Connect
-open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+open sftp://user:password@example.com/ -hostkey="ssh-rsa 2048 xxxxxxxxxxx..."
# Change remote directory # Change remote directory
cd /home/user cd /home/user
Line 78: Line 80:
        UserName = "user"         UserName = "user"
        Password = "password"         Password = "password"
-        SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"+        SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
    }     }
Line 94: Line 96:
        # Download file to the local directory d:\         # Download file to the local directory d:\
        # Note use of absolute path         # Note use of absolute path
-        $transferResult = $session.GetFiles("/home/user/examplefile.txt", "d:\", $False, $transferOptions)+        $transferResult = 
 + ···········$session.GetFiles("/home/user/examplefile.txt", "d:\", $False, $transferOptions)
        # Throw on any error to emulate the default "option batch abort"         # Throw on any error to emulate the default "option batch abort"
Line 107: Line 110:
    exit 0     exit 0
} }
-catch [Exception]+catch
{ {
-    Write-Host $_.Exception.Message+    Write-Host "Error: $($_.Exception.Message)"
    exit 1     exit 1
} }
</code> </code>

Last modified: by martin