FTP a file if the date matches


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP a file if the date matches
# 1  
Old 06-07-2015
FTP a file if the date matches

Hi,
I am trying to write a script where I need to pull any file if the date is from yesterday. Can you please help me on how to check the dates for the files on the remote server?

Please let me know for any questions.

Thanks
Ajay
This User Gave Thanks to ajayakunuri For This Post:
# 2  
Old 06-07-2015
It will depend on the OSes and the utilities you wish to use...
We cant be more precise not knowing how you think to do things... As there are many options I suppose...
# 3  
Old 06-07-2015
What have you tried so far?
# 4  
Old 06-07-2015
Code:
ftp site <<EOF >file.list
ls -l
EOF

Analyse the contents of file.list to decide what to retrieve.
# 5  
Old 06-08-2015
Hi,
Sorry for not posting my script. Here's my ftp script:
Code:
ftp_script=$(
ftp -n $HOST 2>/dev/null <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd development/Mission\ Critical/Aggregator_Bkp/Post
dir . localfile
quote y
quit
END_SCRIPT
) 2>/dev/null
echo $ftp_script

yesterday=`date "+%m-%d-%Y" -d yesterday`
today=`date "+%m-%d-%Y"`
cat localfile | grep STAR | grep $yesterday > file1.txt
cat file1.txt | awk '{print $4}' > file2.txt
if [ -s file2.txt ] ; then
        echo "File exists"
        file2=`cat file2.txt`
        ftp -n $HOST 2>/dev/null <<END_SCRIPT
        quote USER $USER
        quote PASS $PASSWD
        lcd /data/datatransfer/temp
        cd development/Mission\ Critical/Aggregator_Bkp/Post
        binary
        mget $file2
        quote y
        quit
        END_SCRIPT
else
        echo "No file for yesterday"
fi

But when Im running this, I am getting this error:
./test.sh: line 19: syntax error at line 25: `<<' unmatched

The first part of ftp is working fine and creating the localfile, but the 2nd part if failing.

Please let me know if I need to change anything.

Thanks
Ajay

---------- Post updated at 05:48 PM ---------- Previous update was at 05:43 PM ----------

My bad. There is a trailing white space before END_SCRIPT. It is working now.

Thanks
Ajay
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read latest file name with a date and time and then download from FTP

Hi All, Please help. I have requirement to read the file / folder based on the latest date and download the file and folder. There will be files and folders in the location like 20140630-144422 20140630-144422.csv 20140707-182653 20140707-182653.csv 20140710-183153... (7 Replies)
Discussion started by: Praveen Pandit
7 Replies

2. UNIX for Advanced & Expert Users

Want to download a latest file with current date from FTP location

Dear Friends, I need help to write a shell / perl script to download the files from FTP location, having different file names (date inside the file name). Example: Mar 5 09:24 cfx_03052013_return_file.txt Mar 6 02:13 cfx_03062013_return_file.txt Mar 7 06:40... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

3. UNIX for Dummies Questions & Answers

'No Matches' error in FTP

Hi, I am trying to execute a script as below I am trying to connect to a server through a secure connection and then type the command as below /usr/local/bin/sftp -t 2800 $REMOTE_SERVER $REMOTE_USER <<EOD > $MAINDATA/FTPLog cd $HOME_DOWNLOAD ls `echo $1 |... (3 Replies)
Discussion started by: spari2
3 Replies

4. Shell Programming and Scripting

Find file that matches today's date in filename and move to /tmp in bash

I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Discussion started by: jamesi
1 Replies

5. UNIX for Dummies Questions & Answers

Pipe binary file matches grep results to file

I am using grep to match a pattern, but the output is strange. $ grep -r -o "pattern" * Gives me: Binary file foo1 matches Binary file foo2 matches Binary file foo3 matches To find the lines before/after, I then have to use the following on each file: $ strings foo1 | grep -A1 -B1... (0 Replies)
Discussion started by: chipperuga
0 Replies

6. Shell Programming and Scripting

How to FTP the latest file, based on date, from a remote server through a shell script?

How to FTP the latest file, based on date, from a remote server through a shell script? I have four files to be FTP'ed from remote server. They are of the following format. build1_runtime_mmddyyyy.txt build2_runtime_mmddyyyy.txt build3_runtime_mmddyyyy.txt buifile_count_mmddyyyy.txt ... (9 Replies)
Discussion started by: imran_affu
9 Replies

7. UNIX for Dummies Questions & Answers

adding date to a file during FTP

I have a very basic question here. I have to FTP a file from a AIX unix box to a windows server. But during that I have to rename the file. For example: I have to FTP a file called ORDER.TXT from unix and it should go as ORDER_20090101.TXT on to the windows server. It is not possible to... (5 Replies)
Discussion started by: vara32
5 Replies

8. Shell Programming and Scripting

How do I access the create date from Windows after the file has been FTP'd to UNIX ?

I run an application that creates a hostname_log.txt file on the c:\ of each windows workstation. At the end of each day, these log files are FTP'd to a directory on a UNIX box. When I run "ls -lrt", the timestamp that is displayed is the timestamp that the FTP occured, not the timestamp... (2 Replies)
Discussion started by: gavman99
2 Replies

9. Shell Programming and Scripting

FTP - Get the file date and time on the remote server

I would like to know if there is a way to get the date and timestamp of the file that is being FTP from the remote server using shell script. Currently the get command from FTP will have current date and timestamp. Tried the earlier suggestion 'HardFeed' but still getting the current date and time... (12 Replies)
Discussion started by: gthokala
12 Replies

10. UNIX for Dummies Questions & Answers

ftp copy: preserve source file date stamp

Is there any way to preserve a file's create/mod date stamp when it is "put" via ftp (or even using Fetch) to a Win2K server and a SunOS 5.8 server? For example, if I copy a file with a create/mod date of "01/15/2005 3:36 PM" to my Win2K or SunOS ftp server, the date stamp will change to the... (5 Replies)
Discussion started by: cassj
5 Replies
Login or Register to Ask a Question