FtpClient.OpenRead Method (String, FtpDataType)

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 Stream OpenRead(
	string path,
	FtpDataType type
)
Visual Basic
Public Function OpenRead ( 
	path As String,
	type As FtpDataType
) As Stream
Visual C++
public:
virtual Stream^ OpenRead(
	String^ path, 
	FtpDataType type
) sealed

Parameters

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

Return Value

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

Implements

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

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