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 IAsyncResult BeginOpenAppend(
string path,
AsyncCallback callback,
Object state
) |
Visual Basic |
---|
Public Function BeginOpenAppend (
path As String,
callback As AsyncCallback,
state As Object
) As IAsyncResult |
Visual C++ |
---|
public:
virtual IAsyncResult^ BeginOpenAppend(
String^ path,
AsyncCallback^ callback,
Object^ state
) sealed |
Return Value
Type:
IAsyncResultIAsyncResult
Implements
IFtpClient..::..BeginOpenAppend(String, AsyncCallback, Object)
Examples
C# |
Copy
|
using System;
using System.Net;
using System.Net.FtpClient;
using System.IO;
using System.Threading;
namespace Examples {
public static class BeginOpenAppendExample {
static ManualResetEvent m_reset = new ManualResetEvent(false);
public static void BeginOpenAppend() {
using (FtpClient conn = new FtpClient()) {
m_reset.Reset();
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.BeginOpenAppend("/path/to/file",
new AsyncCallback(BeginOpenAppendCallback), conn);
m_reset.WaitOne();
conn.Disconnect();
}
}
static void BeginOpenAppendCallback(IAsyncResult ar) {
FtpClient conn = ar.AsyncState as FtpClient;
Stream istream = null, ostream = null;
byte[] buf = new byte[8192];
int read = 0;
try {
if (conn == null)
throw new InvalidOperationException("The FtpControlConnection object is null!");
ostream = conn.EndOpenAppend(ar);
istream = new FileStream("input_file", FileMode.Open, FileAccess.Read);
while ((read = istream.Read(buf, 0, buf.Length)) > 0) {
ostream.Write(buf, 0, read);
}
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
finally {
if (istream != null)
istream.Close();
if (ostream != null)
ostream.Close();
m_reset.Set();
}
}
}
}
|
See Also