Differences
This shows you the differences between the selected revisions of the page.
2024-10-03 | 2024-10-03 (current) | ||
1 (196.247.224.141) (hidden) (untrusted) | web anchor (martin) | ||
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 73: | Line 70: | ||
There are also [[library_examples|other C# examples]]. | There are also [[library_examples|other C# examples]]. | ||
- | &lt;code csharp&gt; | + | <code csharp> |
using System; | using System; | ||
using WinSCP; | using WinSCP; | ||
Line 87: | Line 84: | ||
{ | { | ||
Protocol = Protocol.Sftp, | Protocol = Protocol.Sftp, | ||
- | HostName = &quot;example.com&quot;, | + | HostName = "example.com", |
- | UserName = &quot;user&quot;, | + | UserName = "user", |
- | Password = &quot;mypassword&quot;, | + | Password = "mypassword", |
- | SshHostKeyFingerprint = &quot;ssh-rsa 2048 xxxxxxxxxxx...&quot; | + | SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." |
}; | }; | ||
Line 104: | Line 101: | ||
TransferOperationResult transferResult; | TransferOperationResult transferResult; | ||
transferResult = | transferResult = | ||
- | session.PutFiles(@&quot;d:\toupload\*&quot;, &quot;/home/user/&quot;, false, transferOptions); | + | session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions); |
// Throw on any error | // Throw on any error | ||
Line 112: | Line 109: | ||
foreach (TransferEventArgs transfer in transferResult.Transfers) | foreach (TransferEventArgs transfer in transferResult.Transfers) | ||
{ | { | ||
- | Console.WriteLine(&quot;Upload of {0} succeeded&quot;, transfer.FileName); | + | Console.WriteLine("Upload of {0} succeeded", transfer.FileName); |
} | } | ||
} | } | ||
Line 120: | Line 117: | ||
catch (Exception e) | catch (Exception e) | ||
{ | { | ||
- | Console.WriteLine(&quot;Error: {0}&quot;, e); | + | Console.WriteLine("Error: {0}", e); |
return 1; | return 1; | ||
} | } | ||
} | } | ||
} | } | ||
- | &lt;/code&gt; | + | </code> |
==== [[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]]. | ||
- | &lt;code vbnet&gt; | + | <code vbnet> |
Imports WinSCP | Imports WinSCP | ||
Line 142: | Line 139: | ||
With sessionOptions | With sessionOptions | ||
.Protocol = Protocol.Sftp | .Protocol = Protocol.Sftp | ||
- | .HostName = &quot;example.com&quot; | + | .HostName = "example.com" |
- | .UserName = &quot;user&quot; | + | .UserName = "user" |
- | .Password = &quot;mypassword&quot; | + | .Password = "mypassword" |
- | .SshHostKeyFingerprint = &quot;ssh-rsa 2048 xxxxxxxxxxx...&quot; | + | .SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..." |
End With | End With | ||
Line 158: | Line 155: | ||
Dim transferResult As TransferOperationResult | Dim transferResult As TransferOperationResult | ||
transferResult = | transferResult = | ||
- | session.PutFiles(&quot;d:\toupload\*&quot;, &quot;/home/user/&quot;, False, transferOptions) | + | session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions) |
' Throw on any error | ' Throw on any error | ||
Line 165: | Line 162: | ||
' Print results | ' Print results | ||
For Each transfer In transferResult.Transfers | For Each transfer In transferResult.Transfers | ||
- | Console.WriteLine(&quot;Upload of {0} succeeded&quot;, transfer.FileName) | + | Console.WriteLine("Upload of {0} succeeded", transfer.FileName) |
Next | Next | ||
End Using | End Using | ||
Line 171: | Line 168: | ||
Return 0 | Return 0 | ||
Catch e As Exception | Catch e As Exception | ||
- | Console.WriteLine(&quot;Error: {0}&quot;, e) | + | Console.WriteLine("Error: {0}", e) |
Return 1 | Return 1 | ||
End Try | End Try | ||
Line 178: | Line 175: | ||
End Class | End Class | ||
- | &lt;/code&gt; | + | </code> |
==== [[powershell]] PowerShell Example ==== | ==== [[powershell]] PowerShell Example ==== | ||
Line 205: | Line 202: | ||
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 |