PowerTCP FTP for .NET
Get(String,Int64,Stream) Method
Example 



An absolute or relative path to the source file on the server.
Restart marker from which the data transfer should start.
Stream to write file data to.
Starts download at the specified offset and writes to the destination Stream.
Syntax
Public Overloads Function Get( _
   ByVal remotePath As String, _
   ByVal remoteOffset As Long, _
   ByVal localDestination As Stream _
) As CopyResult
Dim instance As Ftp
Dim remotePath As String
Dim remoteOffset As Long
Dim localDestination As Stream
Dim value As CopyResult
 
value = instance.Get(remotePath, remoteOffset, localDestination)

Parameters

remotePath
An absolute or relative path to the source file on the server.
remoteOffset
Restart marker from which the data transfer should start.
localDestination
Stream to write file data to.

Return Value

CopyResult containing the result of the operation.
Remarks

The destination Stream is not closed after use.

DataIsBusy returns true while this method executes.

Example
The following example demonstrates restarting/resuming a Get.
/// <summary>
/// Resumes (or starts) a Get operation
/// </summary>
/// <param name="myFtp">A connected and authenticated Ftp instance</param>
/// <param name="remotePath">An absolute or relative path to the file on the server</param>
/// <param name="localPath">The download location</param>
/// <returns>The CopyResult of the operation</returns>
public CopyResult RestartGet(Ftp myFtp, string remotePath, string localPath)
{
    //Ensure that the Ftp object is in binary/image transfer mode
    myFtp.SetType(FileType.Image);
    
    //Create a new file, or open the existing file
    using (FileStream fs = File.OpenWrite(localPath))
    {
        //Set the stream to the correct position
        fs.Position = fs.Length;
        //Start/resume the transfer, and (optionally) return the result
        return myFtp.Get(remotePath, fs.Position, fs);
    }
}
''' <summary>
''' Resumes (or starts) a Get operation
''' </summary>
''' <param name="myFtp">A connected and authenticated Ftp instance</param>
''' <param name="remotePath">An absolute or relative path to the file on the server</param>
''' <param name="localPath">The download location</param>
''' <returns>The CopyResult of the operation</returns>
Public Function RestartGet(ByVal myFtp As Ftp, ByVal remotePath As String, ByVal localPath As String) As CopyResult
    'Ensure that the Ftp object is in binary/image transfer mode
    myFtp.SetType(FileType.Image)

    'Create a new file, or open the existing file
    Using fs As FileStream = File.OpenWrite(localPath)
        'Set the stream to the correct position
        fs.Position = fs.Length
        'Start/resume the transfer, and (optionally) return the result
        Return myFtp.Get(remotePath, fs.Position, fs)
    End Using
End Function
See Also

Reference

Ftp Class
Ftp Members
Overload List


PowerTCP FTP for .NET Documentation Version 6.1
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic