BladeSystem Forums Have Moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

how to get output of an ftp command into a variable

Occasional Advisor

how to get output of an ftp command into a variable

Hi I am using the below command for getting the files from remote server using ftp.
message1=`ftp -i -n -v ${server} >> $LOG < user $USERNAME $PASSWORD
ascii
umask 022
cd $FROM_DIRECTORY
lcd $TO_DIRECTORY/$dt_stamp_yday
ls
mget *.txt
bye
EOF`

It is running successfully. But now I want to download the files based on time.

JRF (Forum member) suggested modtime command to get the modified time of remote file.

Now my question is I want to take output of modtime command to a variable so that I can refer that variable in the script.

Please tell me how can I do that.
3 REPLIES
Acclaimed Contributor

Re: how to get output of an ftp command into a variable

>I want to take output of modtime command to a variable so that I can refer that variable in the script.

You can get the output of ls into a file:
ls [remote-directory] [local-file]

modtime doesn't seem to be able to redirect the output. With your above message1=$(ftp ...) you can capture that output and the parse it.
Acclaimed Contributor

Re: how to get output of an ftp command into a variable

[ Edited ]

Hi:

In a reply I made in your previous thread, I wrote, "You could use something like 'dir' to collect a listing (with dates) of the files in a directory and then parse that list, though."

http://h30499.www3.hp.com/t5/System-Administration/Download-files-to-local-server-using-ftp-script-based-on-date/m-p/4735316#M386809


Since you are redirecting your FTP session output to a file (${LOG}) you can parse ('grep', 'awk', 'perl') that after the FTP session ends and thus deliver the information you want to the encapsulating script. I would think that this should include the response from 'modtime'. If so, you will need to parse it out of the ${LOG} output.

I don't see the value of using 'message1' to collect information.

Regards!

...JRF...

Highlighted
Occasional Advisor

Re: how to get output of an ftp command into a variable

ThanQ James and Dennis,

I will do the parsing.

Actually I am searching for a way to directly get the output of ftp command like dir,pwd into a variable.

It seems there is no direct way other than parsing.