ftp - How to download files which created today?

Hello experts,

I have written following script to download files which created today.

Unfortunately, it's not working.

test.ksh:

#Defining variables
USR='xxx'
PASSWD='yyyy'
HT='test.test.com'
FILE='S*.pdf'
XFILE=$(echo find . -type f -mtime 0)
ZFILE=$(echo ls -tR|grep 'Jun  8')
DIRNAME='/output_files/2010'

#Connecting to ftp site and downloading the file
ftp -n -i -v $HT <<END_SCRIPT
quote USER $USR
quote PASS $PASSWD
cd $DIRNAME
pwd
mget $ZFILE  
bye
END_SCRIPT
ls -l

I also tried:

mget $XFILE

It transfers all files.

I like to download only those files which created today.

Any suggention/code would be grealy appreciated.

Thanks in advance!!
Dip

I am not sure '-mtime 0' will give you what you want. I found some code on the Internet to get today's file and tested it on my machine:

touch -t `date +%m%d0000` testfile
find . -type f -newer testfile

Make sure you test the code to see you are getting the file names in XFILE before you try the 'ftp' stuff.

Thanks.

take a look to my suggestion to find files that are not older then 1 day:

find / -type f -mtime -1

hope that help

Thanks guys for helping me.

I tried research3's suggetions:

 
find / -type f -mtime -1

Above statement also returns y'days files.

soleil4716:
Could you pl. write me what is 'testfile'? How to test?

 
touch -t `date +%m%d0000` testfile
find . -type f -newer testfile

One thing I like to mention that I am trying to download files from remote FTP server.
One of mine friend said this is only possible with 2 FTP sessions.

Thanks

Dip

But from my point of view you don't have any find command in your ftp environment, therefore you have to create a list locally then grep and get your files.

exp.

I am not expert in scripting. Could you pl. send me some code to do that?

Thanks
Dip

give me only 15 min

Sure!! Thanks for your time and help!!

maybe not the best way but work:)

#!/bin/bash

hostname="ftp.openbsd.com"
username="anonymous"
password="test@.com"

function LsFiles(){
 ftp -i -v -n $hostname <<end_ftp
 	user $username $password
  	cd pub
  	cd OpenBSD
	cd OpenSSH
	ls -la 
	bye
end_ftp
}

LsFiles | grep "$@"  | awk '{print $NF}' > list_of_files.txt

function getFiles(){
 ftp -i -v -n $hostname <<end_ftp
	user $username $password
	cd pub
	cd OpenBSD
	cd OpenSSH
	get $1
	bye
end_ftp
}

for run in $(cat list_of_files.txt)
do
getFiles $run
done 

you have to start the script with the follow command

./ftp.sh "Jul 21"

the script will login to the openbsd server and get files that created on Jun 21th from the OpenSSH directory!

hope that help

1 Like

'testfile' is just a name. You can give it any name you want. It will be an empty file with a modification date set to midnight.

The second command will show all files that are newer than that.

Thanks

---------- Post updated at 03:25 PM ---------- Previous update was at 09:47 AM ----------

research3:

Thanks for your kind help!! The codes works good.

I have a small question, in the following code it gets list of all files.

If I want only *.pdf files, how that can be done?

I tried

 ls -la *.pdf 

but it did not work.

function LsFiles(){
 ftp -i -v -n $hostname <<end_ftp
 	user $username $password
  	cd pub
  	cd OpenBSD
	cd OpenSSH
	ls -la 
	bye
end_ftp

try this one

ls "*.pdf"

1 Like
ls -al *.pdf 

is working for me. u can also try

find . -name "*.pdf" 

(but this will only check in the currenbt directory)

dazdseg, I'm a little bit confused about you post,
you mean that the command find run local but not in the ftp session, ??

Thanks research3!!

ls "*.pdf"

worked well.