Topic "Issue with -append switch and SFTP"

Author Message
BrianBak
[View user's profile]

Joined: 2015-03-17
Posts: 3
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?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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
[View user's profile]

Joined: 2015-03-17
Posts: 3
Here is the log, thanks!
Append.log (9.29 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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
[View user's profile]

Joined: 2015-03-17
Posts: 3
I was worried that would be the case... Sad

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
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Thanks for sharing your solution.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License