Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

EDIT 2022: It's supported now:
Issue 1358 – Resume and Append in .NET assembly

@Guest: It's not supported yet.

All you can do is to download the remote file, append the contents locally and upload a whole file back.

Or just modify the source code of .NET assembly to add the -append switch.
Guest

Is it possible to append files using the .NET classes?
martin

chal4oye wrote:

If the remote log.txt file already exists on the SFTP server, I need to be able to append whatever new data is contained in the log.txt file???

Use -append switch of put command:
https://winscp.net/eng/docs/scriptcommand_put
chal4oye

The process I listed above can be handled easily but, if the remote process has NOT grabbed and deleted the log.txt file before the local process is automatically triggered again, I will overwrite the remote file, causing data loss.

If the remote log.txt file already exists on the SFTP server, I need to be able to append whatever new data is contained in the log.txt file???
James Wendt

Re: Appending to Existing File using WinSCP Command Line

I have this working but now have basic question number two to ask...

Once I have confirmation that the file has sent, I'd like to move the local file to an archive directory.

How do I continue the script or what is a batch file command that would enable to me say, "If file XYZ was successfully transmitted from the local machine to the remote SFTP server, move file XYZ to archive folder"?

My current script looks like this:
option batch abort
option confirm off
open sftp://username:password@server.somewhere.com
put c:\folder1\folder1\test.txt
exit

Thank you.
Jim
James Wendt

Appending to Existing File using WinSCP Command Line

I have found several references to appending data to existing files with WinSCP but I have been unable to get it to work. I'm technical enough to be dangerous but I can follow directions so I hope somebody can give me the steps I need to make so that I can follow them.

My goal is as follows:

  • Write log data to a file called log.txt on a Windows server
  • Automatically upload log.txt to a remote SFTP server using WinSCP triggered by a timed event
  • Once the file is uploaded, a process on the remote server will automatically grab and delete the remote log.txt file
  • After upload, the local script will delete the log.txt file on the Windows machine

The process I listed above can be handled easily but, if the remote process has NOT grabbed and deleted the log.txt file before the local process is automatically triggered again, I will overwrite the remote file, causing data loss.

If the remote log.txt file already exists on the SFTP server, I need to be able to append whatever new data is contained in the log.txt file on the local Windows machine to the existing log.txt file on the remote server.

Example:
log.txt file on remote server contains:
1111

2222
3333
4444

log.txt on the local server contains:
5555

6666
7777

I want to append the data from the local file I am sending to the remote file so the end result is a log.txt file on the remote server that contains:
1111

2222
3333
4444
5555
6666
7777

I hope I explained this clearly.

I have been digging around in the forums for an answer and I see instructions that get me close but I am hoping somebody can clearly document the steps I need to take to make this happen.

Thank you for your time and I look forward to your answer.

J