Appending to Existing File using WinSCP Command Line

Advertisement

James Wendt
Guest

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

Reply with quote

Advertisement

James Wendt
Guest

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

Reply with quote

chal4oye
Joined:
Posts:
1
Location:
Pakistan

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???

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum