When I first download a file and upload it via SSH.NET, all works fine.
client.DownloadFile(url, x)
Using fs= System.IO.File.OpenRead(x)
sFtpClient.Uploa
After writing to the stream, the stream pointer is at the end of the stream. So when you pass the stream to the .UploadFile
, it reads the stream from the pointer (which is at the end) to the end. Hence, nothing is written. And no error is issued, because everything behaves as designed.
You need to reset the pointer to the beginning, before passing the stream to the .UploadFile
:
Dim ba As Byte() = client.DownloadData(url)
Dim stream As New MemoryStream()
stream.Write(ba, 0, ba.Length)
' Reset the pointer
stream.Position = 0
sFtpClient.UploadFile(stream, fn, True)
An alternative is to use SSH.NET PipeStream
, which has separate read and write pointers.