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.UploadFile(fs, fn, True)
End Using
However I must now (not download the file) but upload a stream of the file:
Dim ba As Byte() = client.DownloadData(url)
Dim stream As New MemoryStream()
stream.Write(ba, 0, ba.Length)
sFtpClient.UploadFile(stream, fn, True)
What is happening is that the UploadFile
method thinks it succeeded, but on the actual FTP, the file is created with size 0KB.
What am I doing wrong please? I tried adding the buffer size too, but it did not work.
I found code on the web. Should I be doing something like this:
client.ChangeDirectory(pFileFolder);
client.Create(pFileName);
client.AppendAllText(pFileName, pContents);