Unix Shell - Get the most recent file in a remote server using FTP script

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2006 > Get the most recent file in a remote server using FTP script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Get the most recent file in a remote server using FTP script
anujairaj

2006-09-26, 7:27 pm

Hi,
I have a few files with a timestamp appended in the end ,in a remote
server,I need to get the most recent one in the ftp scripot.But Iam
unable to do it using :


MOST_RECENT_FILE1=`ls -1t ${FTP_OUTPUT_DIR}${FTP_OUTPUT_FILE1}* | head
-1 `
get ${MOST_RECENT_FILE1} ${FTP_INPUT_DIR}${FTP_INPUT_FILE1}.csv

it says,file not found.
Can anyone help me on this?
thanks

Lie-Algebra

2006-09-26, 7:27 pm

anujairaj a écrit :
> Hi,
> I have a few files with a timestamp appended in the end ,in a remote
> server,I need to get the most recent one in the ftp scripot.But Iam
> unable to do it using :
>
>
> MOST_RECENT_FILE1=`ls -1t ${FTP_OUTPUT_DIR}${FTP_OUTPUT_FILE1}* | head
> -1 `
> get ${MOST_RECENT_FILE1} ${FTP_INPUT_DIR}${FTP_INPUT_FILE1}.csv
>
> it says,file not found.
> Can anyone help me on this?
> thanks
>


Hi,

this cant work, the output of the command ls -lt * | head -1 would ,
consist of a line such as the following :

-rwxr-xr-x 1 user group 748 2006-09-23 12:57 mostRecentFile

To catch the filepath(relative to the rep you are in), you need to pipe
the previous output to obtain something like : ls -lt * | head -1 | awk
'{print $NF}'

I guess you could play with the echo command in your ftp script to see
if the result is relevant to you.

Hope this help.
Lie-Algebra

2006-09-26, 7:27 pm

anujairaj a écrit :
> Hi,
> I have a few files with a timestamp appended in the end ,in a remote
> server,I need to get the most recent one in the ftp scripot.But Iam
> unable to do it using :
>
>
> MOST_RECENT_FILE1=`ls -1t ${FTP_OUTPUT_DIR}${FTP_OUTPUT_FILE1}* | head
> -1 `
> get ${MOST_RECENT_FILE1} ${FTP_INPUT_DIR}${FTP_INPUT_FILE1}.csv
>
> it says,file not found.
> Can anyone help me on this?
> thanks
>


Hi,

this cant work, the output of the command ls -lt * | head -1 would
consist of a line such as the following :

-rwxr-xr-x 1 user group 748 2006-09-23 12:57 mostRecentFile

To catch the filepath(relative to the rep you are in), you need to pipe
the previous output to obtain something like : ls -lt * | head -1 | awk
'{print $NF}'

I guess you could play with the echo command in your ftp script to see
if the result is relevant to you.

Hope this help.
johngnub

2006-09-26, 7:27 pm

Silly question:
Most ( not all ) the ftp shells can do a ls -l "ftp> ls -l" , collect
the info, then do your head/tail,
, Like a 2 pass setup, a) get list, b) read list, c) do more work.

2 cents. JB

Lie-Algebra wrote:
> anujairaj a =E9crit :
>
> Hi,
>
> this cant work, the output of the command ls -lt * | head -1 would
> consist of a line such as the following :
>
> -rwxr-xr-x 1 user group 748 2006-09-23 12:57 mostRecentFile
>
> To catch the filepath(relative to the rep you are in), you need to pipe
> the previous output to obtain something like : ls -lt * | head -1 | awk
> '{print $NF}'
>
> I guess you could play with the echo command in your ftp script to see
> if the result is relevant to you.
>=20
> Hope this help.


Stein Arne Storslett

2006-10-26, 7:16 am

<anujairaj@gmail.com> wrote in <1159295778.286734.68100@b28g2000cwb.googlegroups.com>:
> Hi,
> I have a few files with a timestamp appended in the end ,in a remote
> server,I need to get the most recent one in the ftp scripot.But Iam
> unable to do it using :
>
>
> MOST_RECENT_FILE1=`ls -1t ${FTP_OUTPUT_DIR}${FTP_OUTPUT_FILE1}* | head
> -1 `
> get ${MOST_RECENT_FILE1} ${FTP_INPUT_DIR}${FTP_INPUT_FILE1}.csv
>
> it says,file not found.
> Can anyone help me on this?
> thanks
>


Can you extract more from you script.
How do you set these variables.
How do you call ftp (HERE-document)???
Do you use a regular shell-script, perl, or...?

Generally you need to first log on and list the files, saving the output in a variable.
Then you need to find the file you need, and log in again to retrieve it.

I.e:

OUTPUT=$(ftp -v server
cd $DIRECTORY
ls -l $FILE*
bye
)

FILENAME=$(echo "$OUTPUT" | awk 'file { print $NF}' file=$FILE)

ftp -v server
cd $DIRECTORY
get $FILENAME
bye

*** End example ***

This is hacked together in a rush, and is untested, but you can work on it.

--
Stein Arne
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com