Uploading Guardian file to Tandem/Compaq/HPE NonStop server

664 Views Asked by At

I am using OpenSSH. Below bat file code when called from standalone Java program transfers files properly.

@echo off
del "D:\path\inctf2.txt" /s /f /q
set par1=%1
set par2=%2
set par3=%3
set par4=%4

>>D:\path\inctf2.txt echo lcd %par2%
>>D:\path\inctf2.txt echo cd %par1%
>>D:\path\inctf2.txt echo put %par3% %par4%
>>D:\path\inctf2.txt echo quit 

C:
cd C:\Program Files\OpenSSH-Win64

sftp.exe -b D:\path\inctf2.txt userName@IP >> D:\path\%par3%%para4%.log 2>&1

goto END
:END

But When bat file is called from class file inside war deployed on weblogic server. It fails with below error:
Could not create directory '%systemroot%\system32\config\systemprofile/.ssh'. percent_expand: unknown key %s Connection closed

Copied .ssh folder from windows>User>Administrator to D:\path, provided full control also to User:everyone, but no luck.

Java Code:

processBuilder.command("cmd", "/c", "transfer.bat",cdRemoteDir, localDir_For_fileName, 
fileName, remoteFileName );

Process process = processBuilder.start();

int exitVal = process.waitFor();

Tried below code also with same result:

Runtime.getRuntime().exec(

When executed from command_line:

C:\Program Files\OpenSSH-Win64>user_name@ip_address
Connected to ip_address.
sftp> cd $DVL2.CAFINP
sftp> lcd F:\local_file_path
sftp> put OC130319.001 OC130301 0,500,500,800
Uploading OC130319.001 to /G/DVL2/CAFINP/OC130301
OC130319.001
sftp> ls -lrt OC130301
-*********    0 4294952959 199         16718 Apr 30 10:45 OC130301
sftp>

Finally I moved to WinSCP used below commands in bat file:

C:
cd C:\WinSCP5.13.7
winscp.com /script=script.txt >>D:\path\logs\alpha.txt

open sftp_ppk_auth
cd $DVL2.CAFINP
lcd F:\local_path\
put MANCAF OUT4567,0,500,500,800
exit

sftp_ppk_auth is saved WinSCP session
File was successfully transferred but below error message was recorded to logs:

MANCAF | 217589 KB | 2618.9 KB/s | binary | 100% Transfer was successfully finished, but temporary transfer file 'OUT4567,0,500,500,800.filepart' could not be renamed to target file name 'OUT4567,0,500,500,800'.

2

There are 2 best solutions below

2
schtever On

My guess is that it is attempting to create a new entry in HOME/.ssh/known_hosts and your bat file is inheriting the credentials of the weblogic server, which is why it's trying to create an .ssh directory under %systemroot%\system32\config\systemprofile.

Try suppressing this by adding -o CheckHostIP=no to the sftp command line.

0
Martin Prikryl On

Those additional parameters should actually come as a part of the destination file name (credit goes to @dave_thompson_085).

So no matter, what SFTP client you end up using (JSch, psftp, WinSCP), use a target file name like:

MANCAF OUT4567,0,500,500,800

With WinSCP, you will need to use -resumesupport=off switch to avoid a transfer via a temporary file name. Otherwise WinSCP will get confused by the non-existence of what it believe is an actual file name, while it is not.

put -resumesupport=off MANCAF OUT4567,0,500,500,800