how to get output of an ftp command into a variable (419 Views)
Reply
Occasional Advisor
Gopi Kishore m
Posts: 11
Registered: ‎10-08-2010
Message 1 of 4 (419 Views)

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.
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,950
Registered: ‎03-06-2006
Message 2 of 4 (419 Views)

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.
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 4 (419 Views)

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-b...


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...

Please use plain text.
Occasional Advisor
Gopi Kishore m
Posts: 11
Registered: ‎10-08-2010
Message 4 of 4 (419 Views)

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.

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation