I'm trying to get "ftp" commands work inside a function written in ksh script; but it seems to be not working!!
Here's the code:
function chk_ftp_path {
IP_ADDR=$1
USER=$2
PASSWORD=$3
FTP_PATH=$4
ftp -ivn $IP_ADDR << EOF
user $USER $PASSWORD
cd $FTP_PATH
quit
EOF
valid_path=$?
.......
.......
}
When I run the main script (that calls the above function written in another script) then the script hangs after encountering "EOF"!! I don't know why? Please advice.
I am actually hard-coding those values in function (only for demo purpose I've shown function accepting values). So the values being passed to the function is not a problem. And I've enabled the debugging too....and this is what it displays!!
+ ftp -ivn ip_addr
+ 0<< \EOF
user user_name passwd
cd /remote/path
quit
EOF
............-> hangs until I press ^C
You said you are calling the script with the function from another script. You should capture what you pass to that script outside of the function, no?
Can we see all the exact script(s) which matches the "set -x" trace.
The trace does not mention a function call.
The trace does not look like it came from "ksh". What Operating System and version is this?
Please check the script for invisible control characters:
I am running the script on red hat Linux. I am calling the calling in normal shell.
ftp -nv hostname <<SCRIPT1
user $user $password
cd /location1
mget *.txt
bye
SCRIPT1
-------> this is where its hanging
return_value=$?
case return_value in
0) echo 'successful file transfer' >> $path/return;;
*) echo 'Error in ftp' >> $path/return;;
esac
when I run the trace, its showing the following statements and i dont see the update to the file $path/return
Connected to Hostname
331 Password required for username.
230 User username logged in.
250 CWD command successful.
221
Make sure SCRIPT1 is at the beginning of the line and perfectly matches <<SCRIPT1. If there's any mistake, the here-document may become the entire script.
Your code after the FTP is wrong, too.
if [ "$?" -eq 0 ]
then
echo 'successful file transfer'
else
echo 'Error in ftp'
fi >> $path/return
Please make sure what when you post your code, you post your real code, all of your real code, word for word, letter for letter, keystroke for keystroke, in code tags!! If I hadn't seen a similar problem recently I'd have never guessed