Differences
This shows you the differences between the selected revisions of the page.
2024-07-06 | 2024-10-03 | ||
web anchor (martin) | 1 (196.247.224.141) (hidden) (untrusted) | ||
Line 1: | Line 1: | ||
+ | 317 | ||
+ | |||
+ | |||
====== WinSCP .NET Assembly and COM Library ====== | ====== WinSCP .NET Assembly and COM Library ====== | ||
The WinSCP .NET assembly ''winscpnet.dll'' 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, FTP, WebDAV, S3 and SCP sessions from .NET languages, such as [[#csharp|C#]], [[#vbnet|VB.NET]], and others, or from automation environments supporting .NET, such as [[library_powershell|PowerShell]], [[library_ssis|SQL Server Integration Services (SSIS)]] and Microsoft Azure WebSites and Functions. | The WinSCP .NET assembly ''winscpnet.dll'' 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, FTP, WebDAV, S3 and SCP sessions from .NET languages, such as [[#csharp|C#]], [[#vbnet|VB.NET]], and others, or from automation environments supporting .NET, such as [[library_powershell|PowerShell]], [[library_ssis|SQL Server Integration Services (SSIS)]] and Microsoft Azure WebSites and Functions. | ||
Line 70: | Line 73: | ||
There are also [[library_examples|other C# examples]]. | There are also [[library_examples|other C# examples]]. | ||
- | <code csharp> | + | &lt;code csharp&gt; |
using System; | using System; | ||
using WinSCP; | using WinSCP; | ||
Line 84: | Line 87: | ||
{ | { | ||
Protocol = Protocol.Sftp, | Protocol = Protocol.Sftp, | ||
- | HostName = "example.com", | + | HostName = &quot;example.com&quot;, |
- | UserName = "user", | + | UserName = &quot;user&quot;, |
- | Password = "mypassword", | + | Password = &quot;mypassword&quot;, |
- | SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." | + | SshHostKeyFingerprint = &quot;ssh-rsa 2048 xxxxxxxxxxx...&quot; |
}; | }; | ||
Line 101: | Line 104: | ||
TransferOperationResult transferResult; | TransferOperationResult transferResult; | ||
transferResult = | transferResult = | ||
- | session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions); | + | session.PutFiles(@&quot;d:\toupload\*&quot;, &quot;/home/user/&quot;, false, transferOptions); |
// Throw on any error | // Throw on any error | ||
Line 109: | Line 112: | ||
foreach (TransferEventArgs transfer in transferResult.Transfers) | foreach (TransferEventArgs transfer in transferResult.Transfers) | ||
{ | { | ||
- | Console.WriteLine("Upload of {0} succeeded", transfer.FileName); | + | Console.WriteLine(&quot;Upload of {0} succeeded&quot;, transfer.FileName); |
} | } | ||
} | } | ||
Line 117: | Line 120: | ||
catch (Exception e) | catch (Exception e) | ||
{ | { | ||
- | Console.WriteLine("Error: {0}", e); | + | Console.WriteLine(&quot;Error: {0}&quot;, e); |
return 1; | return 1; | ||
} | } | ||
} | } | ||
} | } | ||
- | </code> | + | &lt;/code&gt; |
==== [[vbnet]] VB.NET Example ==== | ==== [[vbnet]] VB.NET Example ==== | ||
There are also [[library_examples|other VB.NET examples]]. | There are also [[library_examples|other VB.NET examples]]. | ||
- | <code vbnet> | + | &lt;code vbnet&gt; |
Imports WinSCP | Imports WinSCP | ||
Line 139: | Line 142: | ||
With sessionOptions | With sessionOptions | ||
.Protocol = Protocol.Sftp | .Protocol = Protocol.Sftp | ||
- | .HostName = "example.com" | + | .HostName = &quot;example.com&quot; |
- | .UserName = "user" | + | .UserName = &quot;user&quot; |
- | .Password = "mypassword" | + | .Password = &quot;mypassword&quot; |
- | .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." | + | .SshHostKeyFingerprint = &quot;ssh-rsa 2048 xxxxxxxxxxx...&quot; |
End With | End With | ||
Line 155: | Line 158: | ||
Dim transferResult As TransferOperationResult | Dim transferResult As TransferOperationResult | ||
transferResult = | transferResult = | ||
- | session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions) | + | session.PutFiles(&quot;d:\toupload\*&quot;, &quot;/home/user/&quot;, False, transferOptions) |
' Throw on any error | ' Throw on any error | ||
Line 162: | Line 165: | ||
' Print results | ' Print results | ||
For Each transfer In transferResult.Transfers | For Each transfer In transferResult.Transfers | ||
- | Console.WriteLine("Upload of {0} succeeded", transfer.FileName) | + | Console.WriteLine(&quot;Upload of {0} succeeded&quot;, transfer.FileName) |
Next | Next | ||
End Using | End Using | ||
Line 168: | Line 171: | ||
Return 0 | Return 0 | ||
Catch e As Exception | Catch e As Exception | ||
- | Console.WriteLine("Error: {0}", e) | + | Console.WriteLine(&quot;Error: {0}&quot;, e) |
Return 1 | Return 1 | ||
End Try | End Try | ||
Line 175: | Line 178: | ||
End Class | End Class | ||
- | </code> | + | &lt;/code&gt; |
==== [[powershell]] PowerShell Example ==== | ==== [[powershell]] PowerShell Example ==== | ||
Line 202: | Line 205: | ||
Because WinSCP uses [[license|the GPL license]] it's important to keep the %%GPL%% license file around.((Simply said, keep all files from ''WinSCP-X.X.X-Automation.zip'' package together.)) Your software doesn't have to be licensed under GPL as the WinSCP .NET Assembly is using WinSCP as an executable, via its public [[scripting|scripting interface]], and not as a library. | Because WinSCP uses [[license|the GPL license]] it's important to keep the %%GPL%% license file around.((Simply said, keep all files from ''WinSCP-X.X.X-Automation.zip'' package together.)) Your software doesn't have to be licensed under GPL as the WinSCP .NET Assembly is using WinSCP as an executable, via its public [[scripting|scripting interface]], and not as a library. | ||
+ | |||
+ | 1 |