简体中文

正體中文 (繁體)
Česky
Danish
Deutsch
English
Español (Castellano)
Eesti keel
Français
Hrvatski
Italiano
日本語

Nederlands
olski
!"#$%&&'(
)lovensky
)rpski
*'$+,-&.'+
WinSCP Free SFTP, SCP and FTP client for
Windows
News
Introduction
SSH Client
SFTP Client
FTP Client
Download
Install
Donate
Documentation
/uides
F01020
)cripting
0NE3 4 C56 7i8rary
)creenshots
3ranslations
)upport
WinSCP .NET Assembly and COM Library :: WinSCP http://winscp.net/eng/docs/library
1 of 7 2012-08-03 22:57
Foru9
3racker
History
Contents »
WinSCP .NET Assembly and COM Library
The WinSCP .NET assembly winscp.dll is a .NET wrapper around WinSCP’s scripting
inter:ace that allows your code to connect to a remote machine and manipulate remote files
over STP! SCP! and TP sessions from .NET lan"ua"es! such as C;! <=0NE3! o>er)hell and
others! or from environments supportin" .NET addons! such as )27 )erver Integration )ervices
())I)).
The assembly is also e#posed to C$%! and as such it can be used from variety of other
pro"rammin" lan"ua"es and development environments&e.".! ?)H#hosted active scripting
languages li'e (Script and )*Script! <isual =asic :or 1pplications (<=1)! erl! and Python.
This feature is available only in the latest beta release.
Downloading and Installing the Assembly
irst you need to do>nload and install the asse98ly.
+dvertisements,
Three Steps to Start Using WinSCP .NET Assembly
Create an instance of the WinSCP.SessionOptions class and fill in all necessary
information to allow an automatic connection and authentication of your session.
@0
Create an instance of the WinSCP.Session class. $ptionally you can hoo' handlers of
some events of the class.
A0
WinSCP .NET Assembly and COM Library :: WinSCP http://winscp.net/eng/docs/library
2 of 7 2012-08-03 22:57
$pen the session usin" Session.Open method! passin" instance of your
WinSCP.SessionOptions.
B0
$nce the session is opened! you can use any of the WinSCP.Session 9ethods to
manipulate remote files! e.".!
Session.GetFiles to do>nload :iles!
Session.PutFiles to upload :iles or
Session.SynchronizeDirectories to synchroniCe directories.
Classes
Namespace, WinSCP
Class Description
Ch9odEvent1rgs Provides data for chan"e of permissions event.
Co99andEDecutionEesult -epresents results of )ession0EDecuteCo99and.
FailedEvent1rgs Provides data for Session.Failed event.
File5perationEvent1rgs Provides data for abstract file operation event.
Fileer9issions -epresents .ni#/style remote file permissions.
5perationEvent1rgs Provides data for abstract operation event.
5perationEesult=ase -epresents results of abstract batch operation.
Ee9oteDirectoryIn:o -epresents data about remote directory.
Ee9oteFileIn:o -epresents data about remote file.
Ee9ovalEvent1rgs Provides data for remote file removal event.
Ee9oval5perationEesult -epresents results of file removal 0Session.RemoveFiles1.
)ession -epresents session. Provides methods for manipulatin" remote files.
)essionEDception E#ception associated with the Session.
)ession7ocalEDception E#ception associated with the Session ori"inatin" from this assembly.
)ession5ptions
2efines information to allow an automatic connection and authentication of the session. 3s
used with Session.Open method.
)essionEe9oteEDception E#ception associated with the Session! ori"inatin" from WinSCP console session.
)ynchroniCationEesult -epresents results of synchroni4ation 0Session.SynchronizeDirectories1.
3ouchEvent1rgs Provides data for remote file timestamp chan"e event.
3rans:erEvent1rgs Provides data for file transfer event.
3rans:er5perationEesult -epresents results of file transfer 0Session.GetFiles or Session.PutFiles1.
3rans:er5ptions 2efines options for file transfers.
Examples
WinSCP .NET Assembly and COM Library :: WinSCP http://winscp.net/eng/docs/library
3 of 7 2012-08-03 22:57
C E!am"le
There are also other C; eDa9ples.
using System;
using WinSCP;

class Example
{
public static int Main()
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions {
Protocol = Protocol.Sftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};

using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);

// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;

TransferOperationResult transferResult;
transferResult = session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions);

// Throw on any error
transferResult.Check();

// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}

return 0;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return 1;
}
}
}
#$.NET E!am"le
There are also other <=0NE3 eDa9ples.
Imports System
Imports WinSCP

Friend Class Example

Public Shared Function Main() As Integer

Try
' Setup session options
Dim sessionOptions As New SessionOptions
With sessionOptions
.Protocol = Protocol.Sftp
WinSCP .NET Assembly and COM Library :: WinSCP http://winscp.net/eng/docs/library
4 of 7 2012-08-03 22:57
.HostName = "example.com"
.UserName = "user"
.Password = "mypassword"
.SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
End With

Using session As Session = New Session
' Connect
session.Open(sessionOptions)

' Upload files
Dim transferOptions As New TransferOptions
transferOptions.TransferMode = TransferMode.Binary

Dim transferResult As TransferOperationResult
transferResult = session.PutFiles("d:\toupload\*", "/home/user/", False, transferOptions)

' Throw on any error
transferResult.Check

' Print results
Dim transfer As TransferEventArgs
For Each transfer In transferResult.Transfers
Console.WriteLine("Upload of {0} succeeded", transfer.FileName)
Next
End Using

Return 0
Catch e As Exception
Console.WriteLine("Error: {0}", e)
Return 1
End Try

End Function

End Class
PowerS%ell E!am"le
There are also other o>er)hell eDa9ples.
try
{
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("WinSCP.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.SshHostKey = "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)
}
WinSCP .NET Assembly and COM Library :: WinSCP http://winscp.net/eng/docs/library
5 of 7 2012-08-03 22:57
}
finally
{
# Disconnect, clean up
$session.Dispose()
}

exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
&Scri"t E!am"le
See overall F)cript eDa9ple or any other F)cript eDa9ple.
#$Scri"t E!am"le
See overall <=)cript eDa9ple or any other <=)cript eDa9ple.
#$A E!am"le
See overall <=1 eDa9ple.
Perl E!am"le
See overall erl eDa9ple.
SS'S E!am"le
See overall ))I) eDa9ple.

library.t#t 5 6ast modified, 7 +u" 7897 by :8.9:9.;7.9;:
Searh Do!mentation
WinSCP .NET Assembly and COM Library :: WinSCP http://winscp.net/eng/docs/library
6 of 7 2012-08-03 22:57

This page
Donate
GH G@H GIH GHH
18out donations
"eommend
Tweet
7

4

748
Like
Assoiations
Hosted 8y )ourceForge
?e8hosting
E)) Feed >ith roJect Ne>s
Driven 8y Doku?iki
php==
=ook9ark 6anager
Site desi"n by =lack /ate
?in)C rivacy olicy
?in)C 7icense
WinSCP .NET Assembly and COM Library :: WinSCP http://winscp.net/eng/docs/library
7 of 7 2012-08-03 22:57