Hello,
I don't know if I'm doing something wrong, and there's probably something that I don't understand...
With Rebex 5.0.7733 in a .Net Core 3.1 app.
I'm getting a file, byte by byte, from an Azure Blob Storage. Of course, my end goal is not byte by byte, but for testing purposes, I'm doing that.
I then do a PutFile, for each byte, incrementing the offset. I never have any problem with the first byte. The file is written on the SFTP, and contains my first char. As soon as I increment the offset in PutFile, I get an error. If I let the offset always to 0, my file will be overwritten, correctly, by each byte. So, the stream is ok, the length is ok, the problem is with appending to the file I guess.
the code :
long offset = 0;
long remainingBytes = 0;
long length = 1;
do
{
MemoryStream stream = new MemoryStream();
azUtilities.GetFileStreamBlock(_AzureFileName, offset*length, ref stream, length, out remainingBytes);
stream.Position = 0;
client.PutFile(stream, _SftpFileName, offset*length, stream.Length);
offset++;
stream.Dispose();
} while (remainingBytes > 0);
The error :
2021-04-08 18:42:49.494 DEBUG Sftp(1)[1] SSH: Authentication successful.
2021-04-08 18:42:49.502 DEBUG Sftp(1)[1] SSH: Opening channel 'session' (initial window size: 131072, max packet size: 129024).
2021-04-08 18:42:49.529 DEBUG Sftp(1)[1] SSH: Requesting subsystem 'sftp'.
2021-04-08 18:42:49.555 DEBUG Sftp(1)[6] SSH: Adjusted remote receive window size: 0 -> 1048576.
2021-04-08 18:42:49.569 INFO Sftp(1)[1] Command: SSH_FXP_INIT (4)
2021-04-08 18:42:49.588 INFO Sftp(1)[1] Response: SSH_FXP_VERSION (4, 1 extension)
2021-04-08 18:42:49.590 INFO Sftp(1)[1] Info: Using SFTP v4 on a Windows-like platform.
2021-04-08 18:42:49.594 INFO Sftp(1)[1] Command: SSH_FXP_REALPATH (1, '.')
2021-04-08 18:42:49.651 INFO Sftp(1)[1] Response: SSH_FXP_NAME (1, '/')
2021-04-08 18:42:49.652 INFO Sftp(1)[1] Info: Home directory is '/'.
2021-04-08 18:42:52.571 INFO Sftp(1)[1] Command: SSH_FXP_OPEN (2, '/c_DRV3546_Plateforme_Integration_Biztalk_A/UNIT/l2c/new-file.txt', 26)
2021-04-08 18:42:52.654 INFO Sftp(1)[1] Response: SSH_FXP_HANDLE (2, 0x255775CC9D22E8A6FC31)
2021-04-08 18:42:52.658 DEBUG Sftp(1)[1] Command: SSH_FXP_WRITE (3, 0x255775CC9D22E8A6FC31, 0, 1 byte)
2021-04-08 18:42:52.672 DEBUG Sftp(1)[1] Response: SSH_FXP_STATUS (3, 0, 'The write completed successfully')
2021-04-08 18:42:52.674 INFO Sftp(1)[1] Command: SSH_FXP_CLOSE (4, 0x255775CC9D22E8A6FC31)
2021-04-08 18:42:52.847 INFO Sftp(1)[1] Response: SSH_FXP_STATUS (4, 0, 'The operation completed')
2021-04-08 18:42:54.353 INFO Sftp(1)[1] Command: SSH_FXP_OPEN (5, '/c_DRV3546_Plateforme_Integration_Biztalk_A/UNIT/l2c/new-file.txt', 2)
2021-04-08 18:42:54.409 INFO Sftp(1)[1] Response: SSH_FXP_HANDLE (5, 0xC1CB976A22B3693F8D22)
2021-04-08 18:42:54.410 DEBUG Sftp(1)[1] Command: SSH_FXP_WRITE (6, 0xC1CB976A22B3693F8D22, 1, 1 byte)
2021-04-08 18:42:54.427 INFO Sftp(1)[1] Response: SSH_FXP_STATUS (6, 4, 'Cannot write to a file not opened for writing!')
2021-04-08 18:42:54.478 ERROR Sftp(1)[1] Info: Rebex.Net.SftpException: Failure; Cannot write to a file not opened for writing!.
at hljlg.hzynn.jfphx(jbrvv p0, Type p1)
at Rebex.Net.Sftp.aquhm(tnzlq p0, wwrjk p1, String p2, Stream p3, Int64 p4, Int64 p5, owqet p6)
Do I have to do something to keep the file open for writing??
Or something else?
Thank you,
Jessy