FtpClient.OpenWrite Method (String)

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

Parameters

path
Type: System..::..String
Full or relative path of the file

Return Value

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

Implements

IFtpClient..::..OpenWrite(String)

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