Class ScpClient
Provides SCP client functionality.
public class ScpClient : BaseClient, IBaseClient, IDisposable
- Inheritance
-
ScpClient
- 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 ScpClient class.
public ScpClient(ConnectionInfo connectionInfo)
Parameters
connectionInfoConnectionInfoThe connection info.
Exceptions
- ArgumentNullException
connectionInfois null.
ScpClient(string, int, string, params IPrivateKeySource[])
Initializes a new instance of the ScpClient class.
public ScpClient(string host, int port, string username, params IPrivateKeySource[] keyFiles)
Parameters
hoststringConnection host.
portintConnection port.
usernamestringAuthentication username.
keyFilesIPrivateKeySource[]Authentication private key file(s) .
Exceptions
- ArgumentNullException
keyFilesis null.- ArgumentException
hostis invalid, -or-usernameis null or contains only whitespace characters.- ArgumentOutOfRangeException
ScpClient(string, int, string, string)
Initializes a new instance of the ScpClient class.
public ScpClient(string host, int port, string username, string password)
Parameters
hoststringConnection host.
portintConnection port.
usernamestringAuthentication username.
passwordstringAuthentication password.
Exceptions
- ArgumentNullException
passwordis null.- ArgumentException
hostis invalid, orusernameis null or contains only whitespace characters.- ArgumentOutOfRangeException
ScpClient(string, string, params IPrivateKeySource[])
Initializes a new instance of the ScpClient class.
public ScpClient(string host, string username, params IPrivateKeySource[] keyFiles)
Parameters
hoststringConnection host.
usernamestringAuthentication username.
keyFilesIPrivateKeySource[]Authentication private key file(s) .
Exceptions
- ArgumentNullException
keyFilesis null.- ArgumentException
hostis invalid, -or-usernameis null or contains only whitespace characters.
ScpClient(string, string, string)
Initializes a new instance of the ScpClient class.
public ScpClient(string host, string username, string password)
Parameters
hoststringConnection host.
usernamestringAuthentication username.
passwordstringAuthentication password.
Exceptions
- ArgumentNullException
passwordis null.- ArgumentException
hostis invalid, orusernameis null or contains only whitespace characters.
Properties
BufferSize
Gets or sets the size of the buffer.
public uint BufferSize { get; set; }
Property Value
- uint
The size of the buffer. The default buffer size is 16384 bytes.
OperationTimeout
Gets or sets the operation timeout.
public TimeSpan OperationTimeout { get; set; }
Property Value
- TimeSpan
The timeout to wait until an operation completes. The default value is negative one (-1) milliseconds, which indicates an infinite time-out period.
RemotePathTransformation
Gets or sets the transformation to apply to remote paths.
public IRemotePathTransformation RemotePathTransformation { get; set; }
Property Value
- IRemotePathTransformation
The transformation to apply to remote paths. The default is DoubleQuote.
Remarks
This transformation is applied to the remote file or directory path that is passed to the
scp command.
See RemotePathTransformation for the transformations that are supplied out-of-the-box with SSH.NET.
Exceptions
- ArgumentNullException
valueis null.
Methods
Download(string, DirectoryInfo)
Downloads the specified directory from the remote host to local directory.
public void Download(string directoryName, DirectoryInfo directoryInfo)
Parameters
directoryNamestringRemote host directory name.
directoryInfoDirectoryInfoLocal 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, 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, Stream)
Downloads the specified file from the remote host to the stream.
public void Download(string filename, Stream destination)
Parameters
filenamestringA relative or absolute path for the remote file.
destinationStreamThe 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(DirectoryInfo, string)
Uploads the specified directory to the remote host.
public void Upload(DirectoryInfo directoryInfo, string path)
Parameters
directoryInfoDirectoryInfoThe directory info.
pathstringA 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.
Upload(FileInfo, string)
Uploads the specified file to the remote host.
public void Upload(FileInfo fileInfo, string path)
Parameters
fileInfoFileInfoThe file system info.
pathstringA relative or absolute path for the remote file.
Exceptions
- ArgumentNullException
fileInfois null.- ArgumentNullException
pathis null.- ArgumentException
pathis a zero-length 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(Stream, string)
Uploads the specified stream to the remote host.
public void Upload(Stream source, string path)
Parameters
Exceptions
- ArgumentNullException
pathis null.- ArgumentException
pathis a zero-length 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.
Events
Downloading
Occurs when downloading file.
public event EventHandler<ScpDownloadEventArgs>? Downloading
Event Type
Uploading
Occurs when uploading file.
public event EventHandler<ScpUploadEventArgs>? Uploading