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

Re: Issue with -append switch and SFTP

Thanks for sharing your solution.
BrianBak

Re: Issue with -append switch and SFTP

I was worried that would be the case... :(

I don't have a choice of SFTP servers so it looks like I have to avoid the -append switch.

I was able to work around the issue by using a combination of get and put commands, I'm pasting my workaround here in case someone else runs in to the same issue and finds this thread, and please let me know if you see anything wrong with the code below. Thanks for your help!

REM ****************************************************
REM This code is to handle appending the new file
REM to the existing file if it exists.

echo Pulling existing file from SFTP server (if exists) and renaming to file1.txt
winscp.com /command "option batch abort" "option confirm off" "open sftp://user:password@server/" "cd DIRECTORY" "get file.txt \\server\share\file1.txt" "exit"

echo Renaming new file to file2.txt so it will append to end of file1.txt
ren \\server\share\file.txt file2.txt

echo Appending new file to existing file.
for /R \\server\share %%f in (file*.txt) do type "%%f" >> \\server\share\output.txt

echo Sending updated file back to SFTP server and changing name back to original file.txt
winscp.com /command "option batch abort" "option confirm off" "open sftp://user:password@server/" "cd DIRECTORY" "put \\server\share\output.txt file.txt" "exit"

echo SFTP completed appending file.

REM ****************************************************
martin

Re: Issue with -append switch and SFTP

I have tested their server. It's just buggy. It's not only the "append" mode that does not work. Choose a different SFTP server software.
BrianBak

Re: Issue with -append switch and SFTP

Here is the log, thanks!
martin

Re: Issue with -append switch and SFTP

I cannot reproduce your problem.

Please attach a full log file showing the problem (using the latest version of WinSCP).

To generate log file, use /log=path_to_log_file command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
BrianBak

Issue with -append switch and SFTP

We are in the process of translating several scripts that were previously utilizing FTP in to SFTP using WinSCP.

A couple of my scripts use the append ftp command. This is supposed to be equivalent to the "put -append" command, but it is not working. It simply overwrites the existing file with information from the new file, but not the whole file.

Example:

FileA.txt

1111
2222
3333

FileB.txt

4444
5555

Command:

winscp.com /command "option batch abort" "option confirm off" "open sftp://user:password@servre/" "cd directory" "put -append FileB.txt FileA.txt" "exit"

Result:

4444
5555
3333


Any ideas?