Class ScpClient
- Namespace
- Renci.SshNet
- Assembly
- Renci.SshNet.dll
Provides SCP client functionality.
public class ScpClient : BaseClient, IBaseClient, IDisposableInheritance
Implements
Inherited Members
Remarks
More information on the SCP protocol is available here: https://github.com/net-ssh/net-scp/blob/master/lib/net/scp.rb.
Known issues in OpenSSH:
- Recursive download (-prf) does not deal well with specific UTF-8 and newline characters.Recursive update does not support empty path for uploading to home directory.
Constructors
ScpClient(ConnectionInfo)
Initializes a new instance of the Renci.SshNet.ScpClient class.
public ScpClient(ConnectionInfo connectionInfo)Parameters
connectionInfoConnectionInfo-
The connection info.
Exceptions
- ArgumentNullException
-
connectionInfois null.
ScpClient(string, int, string, string)
Initializes a new instance of the Renci.SshNet.ScpClient class.
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
public ScpClient(string host, int port, string username, string password)Parameters
hoststring-
Connection host.
portint-
Connection port.
usernamestring-
Authentication username.
passwordstring-
Authentication password.
Exceptions
- ArgumentNullException
-
passwordis null. - ArgumentException
-
hostis invalid, orusernameis null or contains only whitespace characters. - ArgumentOutOfRangeException
-
portis not within System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort.
ScpClient(string, string, string)
Initializes a new instance of the Renci.SshNet.ScpClient class.
public ScpClient(string host, string username, string password)Parameters
hoststring-
Connection host.
usernamestring-
Authentication username.
passwordstring-
Authentication password.
Exceptions
- ArgumentNullException
-
passwordis null. - ArgumentException
-
hostis invalid, orusernameis null or contains only whitespace characters.
ScpClient(string, int, string, params IPrivateKeySource[])
Initializes a new instance of the Renci.SshNet.ScpClient class.
[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")]
public ScpClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)Parameters
hoststring-
Connection host.
portint-
Connection port.
usernamestring-
Authentication username.
keyFilesIPrivateKeySource[]-
Authentication private key file(s) .
Exceptions
- ArgumentNullException
-
keyFilesis null. - ArgumentException
-
hostis invalid, -or-usernameis null or contains only whitespace characters. - ArgumentOutOfRangeException
-
portis not within System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort.
ScpClient(string, string, params IPrivateKeySource[])
Initializes a new instance of the Renci.SshNet.ScpClient class.
public ScpClient(string host, string username, params IPrivateKeySource[] keyFiles)Parameters
hoststring-
Connection host.
usernamestring-
Authentication username.
keyFilesIPrivateKeySource[]-
Authentication private key file(s) .
Exceptions
- ArgumentNullException
-
keyFilesis null. - ArgumentException
-
hostis invalid, -or-usernameis null or contains only whitespace characters.
Properties
BufferSize
Gets or sets the size of the buffer.
public uint BufferSize { get; set; }Property Value
OperationTimeout
Gets or sets the operation timeout.
public TimeSpan OperationTimeout { get; set; }Property Value
RemotePathTransformation
Gets or sets the transformation to apply to remote paths.
public IRemotePathTransformation RemotePathTransformation { get; set; }Property Value
Remarks
This transformation is applied to the remote file or directory path that is passed to the
scp command.
See Renci.SshNet.RemotePathTransformation for the transformations that are supplied out-of-the-box with SSH.NET.
Exceptions
- ArgumentNullException
-
valueis null.
Methods
Download(string, FileInfo)
Downloads the specified file from the remote host to local file.
public void Download(string filename, FileInfo fileInfo)Parameters
Exceptions
- ArgumentNullException
-
fileInfois null. - ArgumentException
-
filenameis null or empty. - ScpException
-
filenameexists on the remote host, and is not a regular file. - SshException
-
The secure copy execution request was rejected by the server.
- SshConnectionException
-
Client is not connected.
Download(string, DirectoryInfo)
Downloads the specified directory from the remote host to local directory.
public void Download(string directoryName, DirectoryInfo directoryInfo)Parameters
directoryNamestring-
Remote host directory name.
directoryInfoDirectoryInfo-
Local directory information.
Exceptions
- ArgumentException
-
directoryNameis null or empty. - ArgumentNullException
-
directoryInfois null. - ScpException
-
File or directory with the specified path does not exist on the remote host.
- SshException
-
The secure copy execution request was rejected by the server.
- SshConnectionException
-
Client is not connected.
Download(string, Stream)
Downloads the specified file from the remote host to the stream.
public void Download(string filename, Stream destination)Parameters
filenamestring-
A relative or absolute path for the remote file.
destinationStream-
The System.IO.Stream to download the remote file to.
Exceptions
- ArgumentException
-
filenameis null or contains only whitespace characters. - ArgumentNullException
-
destinationis null. - ScpException
-
filenameexists on the remote host, and is not a regular file. - SshException
-
The secure copy execution request was rejected by the server.
- SshConnectionException
-
Client is not connected.
Upload(Stream, string)
Uploads the specified stream to the remote host.
public void Upload(Stream source, string path)Parameters
sourceStream-
The System.IO.Stream to upload.
pathstring-
A relative or absolute path for the remote file.
Exceptions
- ArgumentNullException
-
pathis null. - ArgumentException
-
pathis a zero-length System.String. - ScpException
-
A directory with the specified path exists on the remote host.
- SshException
-
The secure copy execution request was rejected by the server.
- SshConnectionException
-
Client is not connected.
Upload(FileInfo, string)
Uploads the specified file to the remote host.
public void Upload(FileInfo fileInfo, string path)Parameters
fileInfoFileInfo-
The file system info.
pathstring-
A relative or absolute path for the remote file.
Exceptions
- ArgumentNullException
-
fileInfois null. - ArgumentNullException
-
pathis null. - ArgumentException
-
pathis a zero-length System.String. - ScpException
-
A directory with the specified path exists on the remote host.
- SshException
-
The secure copy execution request was rejected by the server.
- SshConnectionException
-
Client is not connected.
Upload(DirectoryInfo, string)
Uploads the specified directory to the remote host.
public void Upload(DirectoryInfo directoryInfo, string path)Parameters
directoryInfoDirectoryInfo-
The directory info.
pathstring-
A relative or absolute path for the remote directory.
Exceptions
- ArgumentNullException
-
directoryInfois null. - ArgumentNullException
-
pathis null. - ArgumentException
-
pathis a zero-length string. - ScpException
-
pathdoes not exist on the remote host, is not a directory or the user does not have the required permission. - SshException
-
The secure copy execution request was rejected by the server.
- SshConnectionException
-
Client is not connected.
Downloading
Occurs when downloading file.
public event EventHandler<ScpDownloadEventArgs>? DownloadingEvent Type
Uploading
Occurs when uploading file.
public event EventHandler<ScpUploadEventArgs>? Uploading