We have linux scripts to do SFTP via preshared keys but recently a vendor is requiring the key and a password, I guess it is similar to two factor authentication. So the vendor authenticates with the preshared key and then prompts for a password. Until the password is entered, you are only partially authenticated. So my standard scripts are not working. To get around that, I discovered lftp
can pass the password in a script and solves the problem of scripting putting and getting a file. Here is my script:
#!/bin/sh
# ###########################
# Parameters
# $1 Source Directory
# $2 Source File
# $3 Target IP
# $4 Target File
# $5 Target Directory
# $6 Mode (binary or ascii)
# $7 User
# $8 Pwd
# ###########################
lftp sftp://$7:$8@$3 -e "cd $5; put $1$2; bye"
This script is called from an SAP abap program by calling the function SXPG_COMMAND_EXECUTE
. The return information from shell scripts are usually captured in the return parameter EXEC_PROTOCOL
. All works fine with all other bash scripts but with lftp
, we are getting nothing in the from stdout. We do get errors so I am assuming it is capturing stderr. Any idea why this is?
It has to do with neither SAP nor ABAP. Look at the post here on the ServerFault.com.
The command might be buffering its output, see the accepted answer there and try to unbuffer it.