Problem in Downloading one day old files from FTP site


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in Downloading one day old files from FTP site
# 1  
Old 01-08-2009
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  
Old 01-08-2009
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  
Old 01-09-2009
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  
Old 01-09-2009
Hmmm! Smilie
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  
Old 01-22-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To merge files on FTP site before getting them

I have a job that connects to FTP site, rename, get, delete a file and then process it. The renaming is done in consideration of this is one file name into which data is being accumulated many times within 24 hour cycle. This is what happens now: ftp -i $FTPHOST <<-EOF ren... (3 Replies)
Discussion started by: migurus
3 Replies

2. SCO

FTP problem with site exec command

Hello dear Users, I am for the first time in this forum. I come from Germany. Please excuse my bad englisch. My OS is SCO open Server Release 5. I have a problem whith FTP and the command "site exec" if I use the command "ftp> site chmod 777 /tmp/startkpf.sc 200 CHMOD command successful. ... (8 Replies)
Discussion started by: fla5do
8 Replies

3. UNIX for Dummies Questions & Answers

current day remote files from FTP

Hi All, I have to work on a korn shell script to pick up only the current day files dropped on the remote server (using ftp). The file do not have daytimestamp on it. It has to be based on server time (AIX) The file naming convention is "test_file.txt" When I log in into the ftp account... (15 Replies)
Discussion started by: pavan_test
15 Replies

4. Shell Programming and Scripting

Batch downloading images from a site.

So there is a forum thread (with 100+ pages)where people have posted images, which on a 3rd party site like imgur or imageshack. I'm trying to download all those images. I tried wget -r -l1 --no-parent -nH -nd -P/tmp -A".gif,.jpg" LINK but this doesn't download it. Does anything know a... (1 Reply)
Discussion started by: Howkisl
1 Replies

5. Shell Programming and Scripting

Downloading FTP Files

Hi every one, I have the requirement to download the files from FTP and move those files to unix box. Once after coping the files, i need to remove the files in FTP. I'm a newbie in Unix script. Can you please suggest a script for this.. Thanks in advance.. (2 Replies)
Discussion started by: Murali4u
2 Replies

6. Shell Programming and Scripting

Expect - get, then move files within FTP site?

Trying to do the following, and it looks like Expect is probably my best bet. Any help greatly appreciated 1) Log onto ftp site 2) Go to folder 3) GET all files matching basename*.txt 4) MOVE those files to a subfolder on the ftp site. I don't need to move it on MY computer, I want to move... (2 Replies)
Discussion started by: mbourgon
2 Replies

7. Shell Programming and Scripting

shell script - ftp downloading serveral files without mget

Hello guys, i'm searching for a solution how to download all files from root-directory of an ftp-server through an ftp proxy getting through the ftp proxy and download one file with get ist no problem, but mget * does nothing! ftp -n -i -v <<EOF open proxyHost proxyPort user... (19 Replies)
Discussion started by: macProgger23
19 Replies

8. Shell Programming and Scripting

Download previous day files through FTP

Hi All, I have a scenario where I need to download the previous day modified files from other server to my server through FTP . Could any one please send me the shell script for the same. I used the following but I dont know how to proceed after this. ftp -n -i -v $IP <<ENDOFinPUT >>... (3 Replies)
Discussion started by: sarathchandrach
3 Replies

9. Shell Programming and Scripting

script for download files from ftp site

I'm new to scripting. I'm trying to write a script to download files from ftp site, the following is the script and the message i get after running the script. no files were downloaded :( Thanks advance! script: #!/usr/bin/ksh DAY=`date --date="-1 days" +%y%m%d` ftp -v -n "ftp.address" <<... (5 Replies)
Discussion started by: tiff-matt
5 Replies

10. Shell Programming and Scripting

Pulling a list of files from FTP site in a shell script

Hi, I am writting a shell script which will pull a list files (mentioned in one file 1.txt) from external FTP site (for ex: ftp://abcd.efghijk.com/). The 1.txt is in my local unix directory. I have username and password to connect the external FTP site. Also before I pull the files, I need... (0 Replies)
Discussion started by: spatra
0 Replies
Login or Register to Ask a Question