Problem in Downloading one day old files from FTP site

HI,

I'm downloading one day old files from ftp site.

Below is my script
----------------------------

printf "open $HOST \n" > ftp.cmd
printf "user $USER $PASSWD\n" >> ftp.cmd
printf "bin\n" >> ftp.cmd
#printf "cd /Models/\n" >> ftp.cmd
printf "prompt\n" >> ftp.cmd
printf "for oldfile in $(find . -type f -mtime -1)\n" >> ftp.cmd
printf "do\n" >> ftp.cmd
printf "echo $oldfile\n" >> ftp.cmd
printf "get -i $oldfile\n" >> ftp.cmd
printf "done\n" >> ftp.cmd
printf "bye\n" >> ftp.cmd
ftp -n < ftp.cmd
rm *.cmd

-------------------------------------

But for oldfile in (find . -type f -mtime -1) its giving message like

We only support non-print format, sorry.

Can you please help me.

Regards,
Shekhar

The commands that you're trying to run are actually being run on the remote FTP server. Typically, the FTP daemon process only has a limited subset of commands e.g cd, ls, get, put. I've never seen an FTP daemon that could run a for loop or find command.
You may need to run an 'ls -l' remote command and then process the output textually to determine the files you want before reconnecting to fetch them.
The actual error message seems to be the result of a "form" command

Hope that helps.

Jerry

Hi,

As per yor suggestion I'm trying to download the list of files to text file.
Here I'm not able to output the list to text file when using below command

ls -l remote_directory local_file

But I'm able to output to text file when use simple ls command.

ls remote_directory local_file.

In this case I can not get the ccreated / updated dates. So I cant find the 1 day older files.

I'm using SunOS version:sun4v Unix.

Can you pls help me.

Thanks,
Shekhar

Hmmm! :confused:
The OS on the local server where you're running your script won't affect anything. As I said previously, the 'ls' is actually being run by the remote server FTP daemon, so it all depends how that machine is setup. For the Sun servers that I connect to, both 'ls' and 'ls -l' are viable commands.
Can you rsh (remote shell) to the FTP server and pull back any file information that way,or even use rcp to fetch them?
Can you get the remote file system mounted on your local server so you don't need to use FTP at all?
Or get whatever process generates the files that you're retrieving to date/timestamp them ie <filename>.20090109_152500?

If none of those, I think I'm all out of ideas!

Jerry

Hi,

I'm using the first approach fetching filenames and then determining files which I need to fetch.

I'm connected to the FTP and by using ls -l listing the filenames to local file. And then I'm doing some formatting and removed more than one day old files names. I have done while loop on the filesnames and prepared a string of file names and using that string to get files from FTP site.

I have given final command as
mget "abcd.txt" "efgh.txt" "ijkl.txt"

But this command pulling all the files from the directory.

I tried get command, but its not working.

my script looks like below.

**********************
#! /bin/ksh

printf "open $HOST \n" > ftp.cmd
printf "user $USER $PASSWD\n" >> ftp.cmd
printf "bin\n" >> ftp.cmd
printf "cd Models\n" >> ftp.cmd
printf "prompt\n" >> ftp.cmd
printf "ls -l excel_list.txt\n" >> ftp.cmd
printf "bye\n" >> ftp.cmd
ftp -n < ftp.cmd
rm *.cmd

sed 's/\(01-06-09\.[a-zA-Z0-9_]*\)/\
\1\
/g' excel_list.txt|grep '^01-20-09' >> listDates1.txt

sed 's/[0-9][0-9]-[0-9][0-9]-[0-9][0-9].*[0-9][0-9]:[0-9][0-9][A-Z][A-Z]/ /g' listDates1.txt >> listDates2.txt

sed 's/^ *//g' listDates2.txt >> listDates3.txt

sed 's/^[0-9][0-9]*//g' listDates3.txt >> listDates4.txt

sed 's/^ *//g' listDates4.txt >> excel_files.txt

FTP_LIST=''
while read files
do
FTP_LIST=$FTP_LIST'"'$files'" '
done < "excel_files.txt"

printf "open $HOST \n" > ftp.cmd
printf "user $USER $PASSWD\n" >> ftp.cmd
printf "bin\n" >> ftp.cmd
printf "cd Models\n" >> ftp.cmd
printf "prompt\n" >> ftp.cmd
printf "get $FTP_LIST\n" >> ftp.cmd
printf "bye\n" >> ftp.cmd
ftp -n < ftp.cmd
rm .cmd
*
*******************

Can you suggest how get selected files using FTP.

Thanks