passing parameter to ftp script from output of another ftp

Hi,

I have a ftp script which first gets all the file names and echo's the latest file.

I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is
> Rename Temp File calloc:ICMP port unreachable

here is my script

ftp -nvi $SERVER > ${FILE_DIR}/NavigationftpLog << EOD
user $USER $PWD
cd $PATH
ls its_out*
bye
EOD

#Obtain the latest filename inside the variable filename using sort command
filename=`awk '{if($NF ~ "its_out") {print $NF}}' ${FILE_DIR}/NavigationftpLog | sort -r | sed -ne '1p'`
echo "filename is $filename"

Latest_File=$filename
export Latest_File
ftp -nvi $SERVER > ${FILE_DIR}/Navigationftp2Log << EOD
user $USER $PWD
cd $PATH
lcd $FILE_DIR
ascii
get $Latest_File
bye
EOD

Please advice!

It's only a guess, but the error is reporting in rename...are you trying to retrieve the same file multiple times as you're testing? FTP will typically rename existing files of the same name by appending underscores - maybe it's this that's failing.

I'm not renaming i need the same file name .and the files not even ftp'd once to local server :slight_smile:

  1. Add an "echo Latest_File=$Latest_File" after "Latest_File=$filename". What value do you get? is it what you expected?

  2. If yes, try the second ftp manually with exactly same steps (replace variables with their values). Can you reproduce the error?

When i added echo statement,output gave correct file name and i have tested second ftp manually added the file name to get statement and the error message did not appear. But how to automate this script ??? :frowning:

Please advice!

Frankly that doesn't make any sense. If you have run the exact same commands and its working, then the same should work via script too unless there is some chance of one or more variables not getting initialized to correct values before the 2nd ftp. Try doing echo of each variable being used in 2nd FTP. If that also doesn't yield any clues, I'm out of ideas.