An NDoc Documented Class Library |

# FTPConnection.UploadStream Method (Stream, String)

Upload a stream of data to the FTP server in the current working directory.

public virtual void UploadStream(
Stream srcStream,
string remoteFile
);

#### Parameters

srcStream
  Input stream of data to put.
remoteFile
  Name of remote file in current working directory.

#### Remarks

The stream is closed after the transfer is complete if CloseStreamsAfterTransfer is `true` (the default) and are left open otherwise. If the stream is left open the its position will be at the end of the stream. Use Seek to change the position if required.

The following example uploads the contents of a MemoryStream to the server and downloads the same file into another MemoryStream:

     // build StringStream (defined below) for "Hello world"
    byte[] bytes = Encoding.ASCII.GetBytes("Hello world");
    MemoryStream inStr = new MemoryStream(bytes);

    // upload the stream to a file on the server
    ftpConnection.UploadStream(inStr, "helloworld.txt");
    inStr.Close();

    // create a MemoryStream and download into it
    MemoryStream outStr = new MemoryStream();
    ftpConnection.DownloadStream(outStr, "helloworld.txt");
    outStr.Seek(0, SeekOrigin.Begin);
    string str = Encoding.GetString(outStr.GetBuffer());
    Console.WriteLine(str);
    outStr.Close();

#### See Also

FTPConnection Class | EnterpriseDT.Net.Ftp Namespace | FTPConnection.UploadStream Overload List