Differences
This shows you the differences between the selected revisions of the page.
| 2013-05-14 | 2013-05-15 | ||
| library_transferresumesupport (martin) | library_powershell (martin) | ||
| Line 1: | Line 1: | ||
| ====== WinSCP .NET Assembly and COM Library ====== | ====== WinSCP .NET Assembly and COM Library ====== | ||
| - | The WinSCP .NET assembly ''winscpnet.dll'' (''winscp.dll'' in the releases before the latest beta version) &beta is a .NET wrapper around WinSCP's [[scripting|scripting interface]] that allows your code to connect to a remote machine and manipulate remote files over SFTP, SCP, and FTP sessions from .NET languages, such as [[library#csharp|C#]], [[library#vbnet|VB.NET]], [[library#powershell|PowerShell]] and others, or from environments supporting .NET addons, such as [[library_ssis|SQL Server Integration Services (SSIS)]]. | + | The WinSCP .NET assembly ''winscpnet.dll'' (''winscp.dll'' in the releases before the latest beta version) &beta is a .NET wrapper around WinSCP's [[scripting|scripting interface]] that allows your code to connect to a remote machine and manipulate remote files over SFTP, SCP, and FTP sessions from .NET languages, such as [[library#csharp|C#]], [[library#vbnet|VB.NET]], and others, or from environments supporting .NET, such as [[library_powershell|PowerShell]] and [[library_ssis|SQL Server Integration Services (SSIS)]]. |
| The assembly is also exposed to COM, and as such it can be used from variety of other programming languages and development environments--e.g., [[library_com_wsh|WSH-hosted active scripting languages]] like JScript and VBScript, [[library_vb|Visual Basic for Applications (VBA)]], [[library_perl|Perl]], and Python. | The assembly is also exposed to COM, and as such it can be used from variety of other programming languages and development environments--e.g., [[library_com_wsh|WSH-hosted active scripting languages]] like JScript and VBScript, [[library_vb|Visual Basic for Applications (VBA)]], [[library_perl|Perl]], and Python. | ||
| Line 158: | Line 158: | ||
| ==== [[powershell]] PowerShell Example ==== | ==== [[powershell]] PowerShell Example ==== | ||
| - | There are also [[library_examples|other PowerShell examples]]. | + | See [[library_powershell#example|overall PowerShell example]] or [[library_examples|any other PowerShell example]]. |
| - | + | ||
| - | &beta (* .dll *) | + | |
| - | + | ||
| - | <code powershell> | + | |
| - | try | + | |
| - | { | + | |
| - | # Load WinSCP .NET assembly | + | |
| - | # Use "winscp.dll" for the releases before the latest beta version. | + | |
| - | ····[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null | + | |
| - | + | ||
| - | # Setup session options | + | |
| - | $sessionOptions = New-Object WinSCP.SessionOptions | + | |
| - | $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp | + | |
| - | $sessionOptions.HostName = "example.com" | + | |
| - | $sessionOptions.UserName = "user" | + | |
| - | $sessionOptions.Password = "mypassword" | + | |
| - | $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx" | + | |
| - | + | ||
| - | $session = New-Object WinSCP.Session | + | |
| - | + | ||
| - | try | + | |
| - | { | + | |
| - | # Connect | + | |
| - | $session.Open($sessionOptions) | + | |
| - | + | ||
| - | # Upload files | + | |
| - | $transferOptions = New-Object WinSCP.TransferOptions | + | |
| - | $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary | + | |
| - | + | ||
| - | $transferResult = $session.PutFiles("b:\toupload\*", "./", $False, $transferOptions) | + | |
| - | + | ||
| - | # Throw on any error | + | |
| - | $transferResult.Check() | + | |
| - | + | ||
| - | # Print results | + | |
| - | foreach ($transfer in $transferResult.Transfers) | + | |
| - | { | + | |
| - | Write-Host ("Upload of {0} succeeded" -f $transfer.FileName) | + | |
| - | } | + | |
| - | } | + | |
| - | finally | + | |
| - | { | + | |
| - | # Disconnect, clean up | + | |
| - | $session.Dispose() | + | |
| - | } | + | |
| - | + | ||
| - | exit 0 | + | |
| - | } | + | |
| - | catch [Exception] | + | |
| - | { | + | |
| - | Write-Host $_.Exception.Message | + | |
| - | exit 1 | + | |
| - | } | + | |
| - | </code> | + | |
| ==== [[jscript]] JScript Example ==== | ==== [[jscript]] JScript Example ==== | ||