FtpClient.OpenRead Method (String, FtpDataType, Int64)

System.Net.FtpClient

Collapse image Expand Image Copy image CopyHover image
Opens the specified file for reading

Namespace: System.Net.FtpClient
Assembly: System.Net.FtpClient (in System.Net.FtpClient.dll) Version: 1.0.5064.17461

Syntax

C#
public virtual Stream OpenRead(
	string path,
	FtpDataType type,
	long restart
)
Visual Basic
Public Overridable Function OpenRead ( 
	path As String,
	type As FtpDataType,
	restart As Long
) As Stream
Visual C++
public:
virtual Stream^ OpenRead(
	String^ path, 
	FtpDataType type, 
	long long restart
)

Parameters

path
Type: System..::..String
The full or relative path of the file
type
Type: System.Net.FtpClient..::..FtpDataType
ASCII/Binary
restart
Type: System..::..Int64
Resume location

Return Value

Type: Stream
A stream for reading the file on the server

Implements

IFtpClient..::..OpenRead(String, FtpDataType, Int64)

Examples

C#  Copy imageCopy
using System;
using System.IO;
using System.Net;
using System.Net.FtpClient;

namespace Examples {
    public class OpenReadExample {
        public static void OpenRead() {
            using(FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");

                using(Stream istream = conn.OpenRead("/full/or/relative/path/to/file")) {
                    try {
                        // istream.Position is incremented accordingly to the reads you perform
                        // istream.Length == file size if the server supports getting the file size
                        // also note that file size for the same file can vary between ASCII and Binary
                        // modes and some servers won't even give a file size for ASCII files! It is
                        // recommended that you stick with Binary and worry about character encodings
                        // on your end of the connection.
                    }
                    finally {
                        Console.WriteLine();
                        istream.Close();
                    }
                }
            }
        }
    }
}

See Also