The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Downloadin files not older than 1 day from ftp site shekhar_v4 Shell Programming and Scripting 0 01-08-2009 12:54 PM
shell script to download files from a site? paqman Linux 2 11-26-2008 04:44 PM
script for download files from ftp site tiff-matt Shell Programming and Scripting 5 09-19-2008 03:46 PM
Problem downloading linux kernel 2.6 on to AT91RM9200 yugandhar Linux 1 09-08-2007 07:02 AM
Problem Downloading Red Hat Tradewynd UNIX for Dummies Questions & Answers 2 01-31-2002 01:35 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2009
shekhar_v4 shekhar_v4 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 17
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
  #2 (permalink)  
Old 01-08-2009
JerryHone JerryHone is offline
Registered User
  
 

Join Date: Nov 2006
Location: UK
Posts: 178
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
  #3 (permalink)  
Old 01-09-2009
shekhar_v4 shekhar_v4 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 17
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
  #4 (permalink)  
Old 01-09-2009
JerryHone JerryHone is offline
Registered User
  
 

Join Date: Nov 2006
Location: UK
Posts: 178
Hmmm!
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
  #5 (permalink)  
Old 01-22-2009
shekhar_v4 shekhar_v4 is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 17
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
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0