Session.GetFile Method

Provides System.IO.Stream interface to a remote file contents.

For an efficient download to a physical local file, use Session.GetFileToDirectory and similar methods instead.


public System.IO.Stream GetFile(
    string remoteFilePath,
    TransferOptions options = null
Public Function GetFile(
    remoteFilePath As String,
    Optional options As TransferOptions = Nothing
) As System.IO.Stream


Name Description
string remoteFilePath Full path to the remote file to retrieve.
TransferOptions options Transfer options. Defaults to null, what is an equivalent to new TransferOptions().

Return Value

System.IO.Stream implementation that can be used to read the remote file contents. It implements the Read and Dispose methods only, and other methods derived from these two, like Close and CopyTo. Seeking and cancelling the transfer is not supported. Calling the Dispose (or the Close) will finish downloading the file.


Event Session.FileTransferred is raised for the download. Also raises Session.FileTransferProgress throughout the transfer.

You must dispose the returned stream before trying to use the Session instance again.

Streaming is supported with the SFTP and FTP protocols only.

Last modified: by martin