PowerTCP SSH and SFTP for .NET
Get(String,Int64) Method
Example 




An absolute or relative (from WorkingDirectory) path specifying the source file on the server. Use "/" as the directory delimiter.
The offset into the file from which the copy will start.
Initiates a file copy from the remote server to the local client.
Syntax
'Declaration
 
Public Overloads Function Get( _
   ByVal fileName As String, _
   ByVal offset As Long _
) As Stream
'Usage
 
Dim instance As Sftp
Dim fileName As String
Dim offset As Long
Dim value As Stream
 
value = instance.Get(fileName, offset)
public Stream Get( 
   string fileName,
   long offset
)
public: Stream* Get( 
   string* fileName,
   long offset
) 
public:
Stream^ Get( 
   String^ fileName,
   int64 offset
) 

Parameters

fileName
An absolute or relative (from WorkingDirectory) path specifying the source file on the server. Use "/" as the directory delimiter.
offset
The offset into the file from which the copy will start.

Return Value

A Stream that should be read from and subsequently closed.
Remarks
This method and operations on the returned stream will not raise the Progress event. This method is not thread-safe.
Example
The example below demonstrates how to transfer a file with the streaming interface.
/// <summary>
/// Downloads the specified remote file to the local path.
/// </summary>
/// <param name="mySftp">A connected and authenticated instance of the Sftp class</param>
/// <param name="remotePath">Relative or absolute path to the file on the server</param>
/// <param name="localPath">Local path to download the file to</param>
private static void sftpGetWithStream(Sftp mySftp, string remotePath, string localPath)
{
    using (FileStream output = File.Create(localPath))
    {
        using (Stream input = mySftp.Get(remotePath, 0))
        {
            long total = 0;
            byte[] buffer = new byte[32000];
            int read = -1;
            while (read != 0)
            {
                read = input.Read(buffer, 0, 32000);
                total += read;
                output.Write(buffer, 0, read);
            }
            output.Flush();
        }
    }
}
''' <summary>
''' Downloads the specified remote file to the local path.
''' </summary>
''' <param name="mySftp">A connected and authenticated instance of the Sftp class</param>
''' <param name="remotePath">Relative or absolute path to the file on the server</param>
''' <param name="localPath">Local path to download the file to</param>
Private Shared Sub sftpGetWithStream(ByVal mySftp As Sftp, ByVal remotePath As String, ByVal localPath As String)
    Using output As FileStream = File.Create(localPath)
        Using input As Stream = mySftp.Get(remotePath, 0)
            Dim total As Long = 0
            Dim buffer(31999) As Byte
            Dim read As Integer = -1
            Do While read <> 0
                read = input.Read(buffer, 0, 32000)
                total += read
                output.Write(buffer, 0, read)
            Loop
            output.Flush()
        End Using
    End Using
End Sub
See Also

Reference

Sftp Class
Sftp Members
Overload List


PowerTCP SSH and SFTP for .NET Documentation Version 7.0
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic