Differences
This shows you the differences between the selected revisions of the page.
2015-07-07 | 2015-07-07 | ||
no summary (195.142.129.194) (hidden) | Restored revision 1431594577. Undoing revisions 1436263223, 1436263236, 1436263254, 1436263271, 1436263283, 1436263297, 1436263308, 1436263321. (martin) (hidden) | ||
Line 8: | Line 8: | ||
You can write a script using the assembly that [[guide_custom_commands_automation|extends functionality of WinSCP GUI]]. | You can write a script using the assembly that [[guide_custom_commands_automation|extends functionality of WinSCP GUI]]. | ||
- | == Hacked By $corpion Team == | + | ===== Downloading and Installing the Assembly ===== |
+ | First you need to [[library_install|download and install the assembly]]. | ||
+ | ===== Using Classes from WinSCP .NET Assembly ===== | ||
+ | - Create an instance of the ''[[library_sessionoptions|WinSCP.SessionOptions]]'' class and fill in all necessary information to allow an automatic connection and authentication of your session. | ||
+ | - Create an instance of the ''[[library_session|WinSCP.Session]]'' class. Optionally you can hook handlers of some events of the class. | ||
+ | - Open the session using ''[[library_session_open|Session.Open]]'' method, passing instance of your ''WinSCP.SessionOptions''. | ||
- | + | Once the session is opened, you can use any of the ''WinSCP.Session'' [[library_session#methods|methods]] to manipulate remote files, e.g., | |
- | **Red $corpion** | + | ··* ''[[library_session_getfiles|Session.GetFiles]]'' to [[task_download|download files]], |
- | + | * ''[[library_session_putfiles|Session.PutFiles]]'' to [[task_upload|upload files]] or | |
- | == Hacked By $corpion Team == | + | ··* ''[[library_session_synchronizedirectories|Session.SynchronizeDirectories]]'' to [[task_synchronize_full|synchronize directories]]. |
- | + | ||
- | + | ||
- | + | ||
- | **Red $corpion** | + | |
===== Classes ===== | ===== Classes ===== | ||
Line 48: | Line 49: | ||
| [[library_transferresumesupport|TransferResumeSupport]] | Configures automatic resume/transfer to temporary filename. | | | [[library_transferresumesupport|TransferResumeSupport]] | Configures automatic resume/transfer to temporary filename. | | ||
- | == Hacked By $corpion Team ==· | + | ===== [[example]] Examples ===== |
- | + | See [[library_examples|list of all examples]]. | |
- | + | ||
- | **Red $corpion** | + | |
==== [[csharp]] C# Example ==== | ==== [[csharp]] C# Example ==== | ||
Line 109: | Line 108: | ||
</code> | </code> | ||
- | == Hacked By $corpion Team == | + | ==== [[vbnet]] VB.NET Example ==== |
+ | There are also [[library_examples|other VB.NET examples]]. | ||
+ | <code vbnet> | ||
+ | Imports System | ||
+ | Imports WinSCP | ||
+ | Friend Class Example | ||
- | **Red $corpion** | + | ····Public Shared Function Main() As Integer |
- | ==== [[powershell]] PowerShell Example ==== | + | ········Try |
- | See [[library_powershell#example|overall PowerShell example]] or [[library_examples|any other PowerShell example]]. | + | ············' Setup session options |
+ | ············Dim mySessionOptions As New SessionOptions | ||
+ | ············With mySessionOptions | ||
+ | .Protocol = Protocol.Sftp | ||
+ | .HostName = "example.com" | ||
+ | .UserName = "user" | ||
+ | ···············.Password = "mypassword" | ||
+ | .SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | ||
+ | End With | ||
- | == Hacked By $corpion Team == | + | ············Using mySession As Session = New Session |
+ | ···············' Connect | ||
+ | mySession.Open(mySessionOptions) | ||
+ | ' Upload files | ||
+ | Dim myTransferOptions As New TransferOptions | ||
+ | myTransferOptions.TransferMode = TransferMode.Binary | ||
+ | Dim transferResult As TransferOperationResult | ||
+ | transferResult = mySession.PutFiles("d:\toupload\*", "/home/user/", False, myTransferOptions) | ||
- | **Red $corpion** | + | ················' Throw on any error |
+ | transferResult.Check() | ||
- | ==== [[vbscript]] VBScript Example ==== | + | ················' Print results |
- | See [[library_com_wsh#vbscript|overall VBScript example]] or [[library_examples|any other VBScript example]]. | + | ················For Each transfer In transferResult.Transfers |
+ | ···················Console.WriteLine("Upload of {0} succeeded", transfer.FileName) | ||
+ | ···············Next | ||
+ | ············End Using | ||
- | == Hacked By $corpion Team == | + | ············Return 0 |
+ | Catch e As Exception | ||
+ | Console.WriteLine("Error: {0}", e) | ||
+ | Return 1 | ||
+ | End Try | ||
+ | End Function | ||
+ | End Class | ||
+ | </code> | ||
- | **Red $corpion** | + | ==== [[powershell]] PowerShell Example ==== |
+ | See [[library_powershell#example|overall PowerShell example]] or [[library_examples|any other PowerShell example]]. | ||
- | ==== [[perl]] Perl Example ==== | + | ==== [[jscript]] JScript Example ==== |
- | See [[library_perl#example|overall Perl example]]. | + | See [[library_com_wsh#jscript|overall JScript example]] or [[library_examples|any other JScript example]]. |
- | == Hacked By $corpion Team == | + | ==== [[vbscript]] VBScript Example ==== |
+ | See [[library_com_wsh#vbscript|overall VBScript example]] or [[library_examples|any other VBScript example]]. | ||
+ | ==== [[vba]] VBA Example ==== | ||
+ | See [[library_vb#example|overall VBA example]]. | ||
+ | ==== [[perl]] Perl Example ==== | ||
+ | See [[library_perl#example|overall Perl example]]. | ||
- | **Red $corpion** | + | ==== [[ssis]] SSIS Example ==== |
+ | See [[library_ssis#example|overall SSIS example]]. | ||
===== [[net]] Converting Script to Code Based on .NET Assembly ===== | ===== [[net]] Converting Script to Code Based on .NET Assembly ===== | ||
When you find yourself limited by [[scripting]] capabilities, you may consider [[library_from_script|converting your script to code that uses WinSCP .NET assembly]]. | When you find yourself limited by [[scripting]] capabilities, you may consider [[library_from_script|converting your script to code that uses WinSCP .NET assembly]]. | ||
- | == Hacked By $corpion Team == | + | ===== [[license]] License ===== |
- | + | The WinSCP .NET Assembly is a free library: you can use it, redistribute it and/or modify it under the terms of the [[http://www.mozilla.org/MPL/2.0/|Mozilla Public License Version 2.0]]. | |
- | **Red $corpion** | + | Note that [[library_install#installing|the assembly interacts with WinSCP executable]], which uses a [[license|different license, the GPL]]. Though as WinSCP is used as an executable, via its public [[scripting|scripting interface]], not as a library, all you need to do to comply with the GPL license, is to keep %%GPL%% license file around.((Simply said, keep all files from ''winscpXXXautomation.zip'' package together.)) |