Rebex
Products Downloads Buy Support Contact
Show / Hide Table of Contents

Scp Class

Namespace: Rebex.Net
Assembly: Rebex.Sftp.dll (version 8.0.9673)

Provides methods for communication using legacy SCP protocol. For most scenarios use of Sftp is recommended.

Syntax
public class Scp : NetworkSession, ILogWriterProvider, IDisposable
Inheritance
Object
NetworkSession
Scp
Implements
ILogWriterProvider
IDisposable
Inherited Members
NetworkSession.DefaultLogWriter
NetworkSession.GetHashCode()
NetworkSession.InstanceId
NetworkSession.LogWriter
NetworkSession.ServerName
NetworkSession.ServerPort
NetworkSession.UserName
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)

Remarks

All members of this class are thread-safe.

Examples

See https://www.rebex.net/tiny-sftp-server/ for more info about running a simple local SCP server.
See https://test.rebex.net/ for more info about our free read-only SCP service.
See https://www.rebex.net/sftp.net/features/scp.aspx for more code snippets.

Connecting and authenticating

// initialize new SCP client instance
var client = new Rebex.Net.Scp();

// attach logger for diagnostic purposes
client.LogWriter = new Rebex.FileLogWriter(@"C:\MyData\scp.log");

// register check of server's public key
client.FingerprintCheck += (s, e) =>
{
    // e.Fingerprint check is used here, but e.ServerKey should be validated in production
    string serverFingerprint = e.Fingerprint.ToString(SignatureHashAlgorithm.SHA256);
    e.Accept = (serverFingerprint == knownFingerprint);
};

// connect and authenticate
client.Connect("test.rebex.net");
client.Login("demo", "password");

Downloading files

// download single file from a remote location
client.GetFile("/pub/example/readme.txt", @"C:\MyData\readme.txt");

// download remote directory into "C:\MyData\example" directory
client.Download("/pub/example/", @"C:\MyData\");

Uploading files

// upload single file to a remote location
client.PutFile(@"C:\MyData\readme.txt", "/pub/example/readme.txt");

// upload local directory to a remote directory (as "/incoming/example")
client.Upload(@"C:\MyData\example\", "/incoming/");

Constructors

Name Description
Scp()

Initializes a new instance of the Scp class.

Fields

Name Description
DefaultPort

Default SCP port (22).

Properties

Name Description
DefaultLogWriter

Gets or sets a default log writer used by all new instances of NetworkSession object. Inherited from NetworkSession.

Encoding

Gets or sets the Encoding to use to encode and decode command parameters and server responses.

Fingerprint

Gets the server public key fingerprint (a SHA-256 hash of the server public key).

InstanceId

Gets instance ID (intended for logging purposes). Inherited from NetworkSession.

IsAuthenticated

Gets a value indicating whether the session is authenticated.

IsConnected

Gets a value indicating whether the session is connected.

LocalEndPoint

Gets the local client EndPoint.

LogWriter

Gets or sets the LogWriter used by this object. Inherited from NetworkSession.

Proxy

Gets or sets the network proxy to use to access a remote server.

RemoteEndPoint

Gets the remote server EndPoint.

ServerKey

Gets the server public key.

ServerName

Gets the server name, if available. Inherited from NetworkSession.

ServerPort

Gets the server port, if available. Inherited from NetworkSession.

Session

Gets the SSH session used by this SCP session.

Settings

Gets or sets SCP object settings.

Timeout

Gets or sets the length of time in milliseconds before the operation times out (specify -1 or 0 to indicate that the request does not time out).

UserName

Gets the authenticated user name, if available. Inherited from NetworkSession.

Version

Gets the version of the SCP component.

Methods

Name Description
Bind(SshSession)

Binds the Scp object to an underlying SSH session. This can be used instead of Connect(String)/Login(String, String) methods.

Connect(String)

Connects to the SCP host.

Connect(String, Int32)

Connects to the SCP host.

ConnectAsync(String, Int32, Object)

Begins asynchronous Connect operation. Connects to the SCP host.

ConnectAsync(String, Object)

Begins asynchronous Connect operation. Connects to the SCP host.

CreateDirectory(String)

Creates a directory on the server.

CreateDirectoryAsync(String, Object)

Begins asynchronous CreateDirectory operation. Creates a directory on the server.

Disconnect()

Informs the server that the connection is about to close and terminates the connection.

DisconnectAsync(Object)

Begins asynchronous Disconnect operation. Informs the server that the connection is about to close and terminates the connection.

Dispose()

Disposes the Scp object and all the socket objects.

Dispose(Boolean)

Releases the unmanaged resources used by the Scp and optionally releases the managed resources.

Download(String, String)

Downloads the content of the remote directory (files and all subfolders) to the specified local directory.

DownloadAsync(String, String, Object)

Begins asynchronous Download operation. Downloads the content of the remote directory (files and all subfolders) to the specified local directory.

Finalize()

Finalizer. Called by garbage collector during object destruction.

GetFile(String, Stream)

Downloads the remote file to the data stream.

GetFile(String, String)

Downloads the remote file to the local file, overriding it if it already exists.

GetFileAsync(String, Stream, Object)

Begins asynchronous GetFile operation. Downloads the remote file to the data stream.

GetFileAsync(String, String, Object)

Begins asynchronous GetFile operation. Downloads the remote file to the local file, overriding it if it already exists.

GetHashCode()

Gets hash code for this object. Inherited from NetworkSession.

Login()

Authenticates the user to the server interactively and initializes the SCP session. Uses AuthenticationRequest event to request credentials.

Login(SshGssApiCredentials)

Authenticates to the server using GSSAPI. Kerberos is only supported on Mono. NTLM is supported on Windows and partially on Mono.

Login(String)

Authenticates the user to the server interactively and initializes the SCP session. Uses AuthenticationRequest event to request credentials.

Login(String, SshAuthenticationAgent)

Authenticates the user to the server using his private key and initializes the SCP session.

Login(String, SshPrivateKey)

Authenticates the user to the server using his private key and initializes the SCP session.

Login(String, String)

Authenticates the user to the server and initializes the SCP session.

Login(String, String, SshAuthenticationAgent)

Authenticates the user to the server using a combination of password and public key and initializes the SCP session.

Login(String, String, SshPrivateKey)

Authenticates the user to the server using a combination of password and public key and initializes the SCP session.

LoginAsync(SshGssApiCredentials, Object)

Begins asynchronous Login operation. Authenticates to the server using GSSAPI. Kerberos is only supported on Mono. NTLM is supported on Windows and partially on Mono.

LoginAsync(Object)

Begins asynchronous Login operation. Authenticates the user to the server interactively and initializes the SCP session. Uses AuthenticationRequest event to request credentials.

LoginAsync(String, SshAuthenticationAgent, Object)

Begins asynchronous Login operation. Authenticates the user to the server using his private key and initializes the SCP session.

LoginAsync(String, SshPrivateKey, Object)

Begins asynchronous Login operation. Authenticates the user to the server using his private key and initializes the SCP session.

LoginAsync(String, Object)

Begins asynchronous Login operation. Authenticates the user to the server interactively and initializes the SCP session. Uses AuthenticationRequest event to request credentials.

LoginAsync(String, String, SshAuthenticationAgent, Object)

Begins asynchronous Login operation. Authenticates the user to the server using a combination of password and public key and initializes the SCP session.

LoginAsync(String, String, SshPrivateKey, Object)

Begins asynchronous Login operation. Authenticates the user to the server using a combination of password and public key and initializes the SCP session.

LoginAsync(String, String, Object)

Begins asynchronous Login operation. Authenticates the user to the server and initializes the SCP session.

OnBatchTransferProgress(ScpBatchTransferProgressEventArgs)

Raises the BatchTransferProgress event.

OnTransferProgress(ScpTransferProgressEventArgs)

Raises the TransferProgress event.

PutFile(Stream, String)

Uploads the content of the data stream to the file on the server, overriding it if it already exists.

PutFile(String, String)

Uploads the content of the local file to the file on the server, overriding it if it already exists.

PutFileAsync(Stream, String, Object)

Begins asynchronous PutFile operation. Uploads the content of the data stream to the file on the server, overriding it if it already exists.

PutFileAsync(String, String, Object)

Begins asynchronous PutFile operation. Uploads the content of the local file to the file on the server, overriding it if it already exists.

SetSocketFactory(ISocketFactory)

Sets the socket factory to be used to create communication sockets.

ToString()

Returns a string representation of this object.

Upload(String, String)

Uploads the content of the local directory (files and all subfolders) to the specified remote directory.

UploadAsync(String, String, Object)

Begins asynchronous Upload operation. Uploads the content of the local directory (files and all subfolders) to the specified remote directory.

Events

Name Description
AuthenticationRequest

Occurs when an authentication request is received from the server that cannot be answered programmatically.

BannerReceived

Occurs when a banner message is received from the server.

BatchTransferProgress

Occurs when a significant action occurs in Download(String, String) or Upload(String, String) methods.

FingerprintCheck

Occurs when a fingerprint is received from the server and needs to be validated.

TransferProgress

Occurs when data is send or received.

In This Article
© REBEX ČR s.r.o. Back to top
Privacy policy
Manage cookies