c# - unable to save dynamically created MemoryStream with rebex sftp -
c# - unable to save dynamically created MemoryStream with rebex sftp -
i'm using streamwriter
generate dynamic file , holding in memorystream
. appears alright until go save file using rebex sftp.
the example give on site works fine:
// upload text using memorystream string message = "hello rebex ftp .net!"; byte[] info = system.text.encoding.default.getbytes(message); system.io.memorystream ms = new system.io.memorystream(data); client.putfile(ms, "message.txt");
however code below not:
using (var stream = new memorystream()) { using (var author = new streamwriter(stream)) { writer.autoflush = true; writer.write("test"); } client.putfile(stream, "test.txt"); }
the file "test.txt" saved, empty. need more enable autoflush
work?
after writing memorystream, stream positioned @ end. putfile method reads current position end. that's 0 bytes.
you need position stream @ origin before passing putfile:
... } stream.seek(0, seekorigin.begin); client.putfile(stream, "test.txt");
you may need prevent streamwriter disposing memorystream:
var author = new streamwriter(stream); writer.write("test"); writer.flush(); stream.seek(0, seekorigin.begin); client.putfile(stream, "test.txt");
c# sftp
Comments
Post a Comment