OverwriteMode.Append using PutFile on an SFTP server, doesn't appear to work

Advertisement

wildview
Joined:
Posts:
6
Location:
US

OverwriteMode.Append using PutFile on an SFTP server, doesn't appear to work

Hi, I'm using the WinSCP PutFile programmatically in C# to stream byte data to our SFTP server to create files and using the overwrite mode it works great. However, after the file is created and exists, all subsequent PutFile calls w/ the TransferOptions.Overwrite = OverwriteMode.Append still just overwrite the file. I thought WinSCP using an SFTP server was suppose to support appending data to existing files if using the OverwriteMode.Append mode, is that correct? Can someone help me resolve this problem?

I extracted some code out of our build just to show how the PutFile is being called without the sessionOptions, maybe this will help to shed some light on why the append doesn't work.

Thanks so much!
sessionOptions = new SessionOptions{...}
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
transferOptions.OverwriteMode = OverwriteMode.Append;
 
String data = "Hello World\n";   
byte[] byteArray = Encoding.ASCII.GetBytes(data);
using (MemoryStream stream = new MemoryStream(byteArray))
{
  using (Session session = new Session())
  {
    session.Open(sessionOptions);
    session.PutFile(stream, "/sftpuser/test/test.txt", transferOptions);
  }
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: OverwriteMode.Append using PutFile on an SFTP server, doesn't appear to work

Thanks for your report. Indeed, it does not seem to work. I'll look into it.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,442
Location:
Prague, Czechia

Re: OverwriteMode.Append using PutFile on an SFTP server, doesn't appear to work

It's actually documented that this is not supported:
https://winscp.net/eng/docs/library_transferoptions#overwritemode

Anyway, it was easy to implement, so I've done it:
Issue 2214 – Support appending when streaming file contents to remote server

I'm sending you an email with a development version of WinSCP to the address you have used to register on this forum.

Reply with quote

wildview

Re: OverwriteMode.Append using PutFile on an SFTP server, doesn't appear to work

Awesome, thanks for taking the time to add it in. It'll be nice to have that feature in there. I didn't notice in the doc that the streamed PutFile didn't support it. I use most of the functionality of this pkg for SFTP use and everything else works great. Thanks again!

Reply with quote

Advertisement

wildview

Re: OverwriteMode.Append using PutFile on an SFTP server, doesn't appear to work

Hi Martin, thanks for the 6.2 beta update. The PutFile stream now works to append data. Thanks so much!

Reply with quote

Advertisement

You can post new topics in this forum