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



An absolute or relative path to the source file on the server.
Restart marker from which the data transfer should start.
Lowest level Get method starts a download at the specified offset and returns a Stream to read from.
Syntax
Public Overloads Function Get( _
   ByVal remotePath As String, _
   ByVal remoteOffset As Long _
) As Stream
Dim instance As Ftp
Dim remotePath As String
Dim remoteOffset As Long
Dim value As Stream
 
value = instance.Get(remotePath, remoteOffset)
public Stream Get( 
   string remotePath,
   long remoteOffset
)
public:
Stream^ Get( 
   String^ remotePath,
   int64 remoteOffset
) 

Parameters

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

Return Value

A Stream to read from.
Remarks

The returned stream must be closed before sending more commands over the control connection (the server response to the RETR command is read when the stream is closed).

DataIsBusy returns true until the stream this method opens is closed.

A file retrieval may be aborted by using Connection.Write("ABOR\r\n"), reading the stream until the server closes it, and using Connection.ReadToDelimiter("\r\n") to get the response from the ABOR command sent.

Example
The following example demonstrates using a stream to process data as it is received from the server.
private void streamRecords()
{
    //Establish the stream with 'using' so it is automatically closed and disposed
    using (Stream dataStream = ftp1.Get("myRecords.txt", 0))
    {
        //Set up a buffer to hold the incoming data.
        byte[] buffer = new byte[1024];
        int count = -1;

        //Loop as long as we can read data from the incoming stream.
        do
        {
            //Read data from the stream into the buffer.
            count = dataStream.Read(buffer, 0, buffer.Length);

            //Write any data read into the textbox.
            textBox1.AppendText(System.Text.Encoding.Default.GetString(buffer, 0, count));
        } while (count > 0);
    }
}
Private Sub streamRecords()
    'Establish the stream with 'using' so it is automatically closed and disposed
    Using dataStream As Stream = ftp1.Get("myRecords.txt", 0)
        'Set up a buffer to hold the incoming data.
        Dim buffer(1023) As Byte
        Dim count As Integer = -1

        'Loop as long as we can read data from the incoming stream.
        Do
            'Read data from the stream into the buffer.
            count = dataStream.Read(buffer, 0, buffer.Length)

            'Write any data read into the textbox.
            textBox1.AppendText(System.Text.Encoding.Default.GetString(buffer, 0, count))
        Loop While count > 0
    End Using
End Sub
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