C# Class Granados.Poderosa.SFTP.SFTPClient

SFTP Client

This class is designed to be used in the worker thread.

Some methods block thread while waiting for the response.

Referenced specification:
IETF Network Working Group Internet Draft
SSH File Transfer Protocol
draft-ietf-secsh-filexfer-02 (protocol version 3)
ファイルを表示 Open project: poderosaproject/poderosa Class Usage Examples

Public Methods

Method Description
Close ( ) : void

Close channel.

CreateDirectory ( string path ) : void

Create directory.

DownloadFile ( string remotePath, string localPath, Granados.Poderosa.FileTransfer.Cancellation cancellation, SFTPFileTransferProgressDelegate progressDelegate ) : void

Download a file.

Even if download failed, local file is not deleted.

GetDirectoryEntries ( string directoryPath ) : Granados.Poderosa.SFTP.SFTPFileInfo[]

Gets directory entries in the specified directory path.

GetFileInformations ( string path, bool lstat ) : Granados.Poderosa.SFTP.SFTPFileAttributes

Get file informations.

GetRealPath ( string path ) : string

Gets canonical path.

Init ( ) : void

Initialize

Send SSH_FXP_INIT and receive SSH_FXP_VERSION.

OpenSFTPChannel ( ISSHConnection connection ) : SFTPClient

Opens SFTP channel and creates a new instance.

RemoveDirectory ( string path ) : void

Remove directory.

RemoveFile ( string path ) : void

Remove file.

Rename ( string oldPath, string newPath ) : void

Rename file or directory.

SetPermissions ( string path, int permissions ) : void

Set permissions of the file or directory.

UploadFile ( string localPath, string remotePath, Granados.Poderosa.FileTransfer.Cancellation cancellation, SFTPFileTransferProgressDelegate progressDelegate ) : void

Upload a file.

Private Methods

Method Description
CheckStatus ( ) : void
CloseHandle ( uint requestId, byte handle ) : void
OpenDir ( uint requestId, string directoryPath ) : byte[]
OpenFile ( uint requestId, string filePath, uint flags ) : byte[]
ReadDir ( uint requestId, byte handle ) : ICollection
ReadFile ( uint requestId, byte handle, ulong offset, int length, byte buffer ) : int
ReadFileAttributes ( Granados.IO.SSHDataReader dataReader ) : Granados.Poderosa.SFTP.SFTPFileAttributes
ReadFileInfo ( Granados.IO.SSHDataReader dataReader, Encoding encoding ) : Granados.Poderosa.SFTP.SFTPFileInfo
SFTPClient ( ISSHChannel channel, SFTPClientChannelEventHandler eventHandler ) : System

Constructor

Transmit ( SFTPPacket packet ) : void
TransmitPacketAndWaitForStatusOK ( uint requestId, SFTPPacket packet ) : void
WaitHandle ( SFTPPacket requestPacket, uint requestId ) : byte[]
WaitReady ( ) : bool

Waits for channel status to be "READY". The current thread is blocked until the status comes to "READY" or "CLOSED".

WriteFile ( uint requestId, byte handle, ulong offset, byte buff, int length ) : void

Method Details

Close() public method

Close channel.
public Close ( ) : void
return void

CreateDirectory() public method

Create directory.
Operation failed. Timeout has occured. Invalid status An exception which was thrown while processing the response.
public CreateDirectory ( string path ) : void
path string Directory path to create.
return void

DownloadFile() public method

Download a file.
Even if download failed, local file is not deleted.
Operation failed. Timeout has occured. Invalid status. Error. Error.
public DownloadFile ( string remotePath, string localPath, Granados.Poderosa.FileTransfer.Cancellation cancellation, SFTPFileTransferProgressDelegate progressDelegate ) : void
remotePath string Remote file path to download.
localPath string Local file path to save.
cancellation Granados.Poderosa.FileTransfer.Cancellation An object to request the cancellation. Set null if the cancellation is not needed.
progressDelegate SFTPFileTransferProgressDelegate Delegate to notify progress. Set null if notification is not needed.
return void

GetDirectoryEntries() public method

Gets directory entries in the specified directory path.
Operation failed. Timeout has occured. Invalid status.
public GetDirectoryEntries ( string directoryPath ) : Granados.Poderosa.SFTP.SFTPFileInfo[]
directoryPath string Directory path.
return Granados.Poderosa.SFTP.SFTPFileInfo[]

GetFileInformations() public method

Get file informations.
Operation failed. Timeout has occured. Invalid status An exception which was thrown while processing the response.
public GetFileInformations ( string path, bool lstat ) : Granados.Poderosa.SFTP.SFTPFileAttributes
path string File path.
lstat bool Specifies to use lstat. Symbolic link is not followed and informations about the symbolic link are returned.
return Granados.Poderosa.SFTP.SFTPFileAttributes

GetRealPath() public method

Gets canonical path.
Operation failed. Timeout has occured. Invalid status.
public GetRealPath ( string path ) : string
path string Path to be canonicalized.
return string

Init() public method

Initialize
Send SSH_FXP_INIT and receive SSH_FXP_VERSION.
Timeout has occured. Invalid status An exception which was thrown while processing the response.
public Init ( ) : void
return void

OpenSFTPChannel() public static method

Opens SFTP channel and creates a new instance.
public static OpenSFTPChannel ( ISSHConnection connection ) : SFTPClient
connection ISSHConnection SSH2 connection object
return SFTPClient

RemoveDirectory() public method

Remove directory.
Operation failed. Timeout has occured. Invalid status An exception which was thrown while processing the response.
public RemoveDirectory ( string path ) : void
path string Directory path to remove.
return void

RemoveFile() public method

Remove file.
Operation failed. Timeout has occured. Invalid status An exception which was thrown while processing the response.
public RemoveFile ( string path ) : void
path string File path to remove.
return void

Rename() public method

Rename file or directory.
Operation failed. Timeout has occured. Invalid status An exception which was thrown while processing the response.
public Rename ( string oldPath, string newPath ) : void
oldPath string Old path.
newPath string New path.
return void

SetPermissions() public method

Set permissions of the file or directory.
Operation failed. Timeout has occured. Invalid status An exception which was thrown while processing the response.
public SetPermissions ( string path, int permissions ) : void
path string Path.
permissions int Permissions to set.
return void

UploadFile() public method

Upload a file.
Operation failed. Timeout has occured. Invalid status. Error. Error.
public UploadFile ( string localPath, string remotePath, Granados.Poderosa.FileTransfer.Cancellation cancellation, SFTPFileTransferProgressDelegate progressDelegate ) : void
localPath string Local file path to upload.
remotePath string Remote file path to write.
cancellation Granados.Poderosa.FileTransfer.Cancellation An object to request the cancellation. Set null if the cancellation is not needed.
progressDelegate SFTPFileTransferProgressDelegate Delegate to notify progress. Set null if notification is not needed.
return void