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]].
-&amp;lt;code csharp&amp;gt;+<code csharp>
using System; using System;
using WinSCP; using WinSCP;
Line 87: Line 84:
            {             {
                Protocol = Protocol.Sftp,                 Protocol = Protocol.Sftp,
-                HostName = &amp;quot;example.com&amp;quot;, +                HostName = "example.com", 
-                UserName = &amp;quot;user&amp;quot;, +                UserName = "user", 
-                Password = &amp;quot;mypassword&amp;quot;, +                Password = "mypassword", 
-                SshHostKeyFingerprint = &amp;quot;ssh-rsa 2048 xxxxxxxxxxx...&amp;quot;+                SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx..."
            };             };
Line 104: Line 101:
                TransferOperationResult transferResult;                 TransferOperationResult transferResult;
                transferResult =                 transferResult =
-                    session.PutFiles(@&amp;quot;d:\toupload\*&amp;quot;, &amp;quot;/home/user/&amp;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(&amp;quot;Upload of {0} succeeded&amp;quot;, transfer.FileName);+                    Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
                }                 }
            }             }
Line 120: Line 117:
        catch (Exception e)         catch (Exception e)
        {         {
-            Console.WriteLine(&amp;quot;Error: {0}&amp;quot;, e);+            Console.WriteLine("Error: {0}", e);
            return 1;             return 1;
        }         }
    }     }
} }
-&amp;lt;/code&amp;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]].
-&amp;lt;code vbnet&amp;gt;+<code vbnet>
Imports WinSCP Imports WinSCP
Line 142: Line 139:
            With sessionOptions             With sessionOptions
                .Protocol = Protocol.Sftp                 .Protocol = Protocol.Sftp
-                .HostName = &amp;quot;example.com&amp;quot; +                .HostName = "example.com" 
-                .UserName = &amp;quot;user&amp;quot; +                .UserName = "user" 
-                .Password = &amp;quot;mypassword&amp;quot; +                .Password = "mypassword" 
-                .SshHostKeyFingerprint = &amp;quot;ssh-rsa 2048 xxxxxxxxxxx...&amp;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(&amp;quot;d:\toupload\*&amp;quot;, &amp;quot;/home/user/&amp;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(&amp;quot;Upload of {0} succeeded&amp;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(&amp;quot;Error: {0}&amp;quot;, e)+            Console.WriteLine("Error: {0}", e)
            Return 1             Return 1
        End Try         End Try
Line 178: Line 175:
End Class End Class
-&amp;lt;/code&amp;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 

Last modified: by martin