FtpClient.OpenWrite Method (String, FtpDataType)

System.Net.FtpClient

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

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

Syntax

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

Parameters

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

Return Value

Type: Stream
A stream for writing to the file on the server

Implements

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

Examples

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

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

                using (Stream ostream = conn.OpenWrite("/full/or/relative/path/to/file")) {
                    try {
                        // istream.Position is incremented accordingly to the writes you perform
                    }
                    finally {
                        ostream.Close();
                    }
                }
            }
        }
    }
}

See Also