File listing from remote to local directory | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

File listing from remote to local directory

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-15-2012
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Last Activity: 25 June 2012, 9:09 PM EDT
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
File listing from remote to local directory

Hello,

I have a file at remote server. I have to select only current day's files that are dropped on ftp server. The files do not have date or timestamp on them.

so I plan to get the file listing from remote server to the local server. Based on file listing date I can find out when the files are dropped. (by comparing with the current day's date)

I have a ftp script and I am using these commands to get the file listing date to the local directory.


Code:
ftp <host_name>
ftp <user>
ftp <password>
dir <dir>
200 PORT command successful
150 Opening ASCII mode data connection for file list
-rw-rw-r--   1 <uuu>  <kkk>   160384 Apr 13  19:38 walmart.txt
226 Transfer complete
ftp> lcd <local_dir>
ftp> dir walgreens.txt lcd
output ot local-file: lcd? y
200 PORT command successful
150 Opening ASCII mode data connection for file list
226 Transfer complete
ftp> bye

now I find lcd on my local directory,


Code:
-rw-r--r--    1 <usr>   <usr>              69 Apr 15 16:49 lcd

And when I do "vi lcd" (or "more lcd") I find this,


Code:
-rw-rw-r--   1 <uuu>  <kkk>   160384 Apr 13  19:38 walmart.txt

Can somone please tell me, after I get the file to local directory, how do I find out if the file is current day file using a korn shell script.

Thanks
pavan

Last edited by Scrutinizer; 04-15-2012 at 06:41 PM.. Reason: code tags
Sponsored Links
    #2  
Old 04-16-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 Posts
This should work providing that none of the filenames contain space characters:

Code:
TODAY="`date '+%b %e'`"        # Mmm dD
grep "${TODAY}" lcd | awk '{print $9}' | while read filename
do
        echo "File dated today: ${filename}"
done


Tip: When you come to script your ftp directory enquiry note that invoking ftp as ftp -i will stop it asking the question about creating the directory listing file.
Sponsored Links
    #3  
Old 04-17-2012
pavan_test pavan_test is offline
Registered User
 
Join Date: Oct 2005
Last Activity: 25 June 2012, 9:09 PM EDT
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post
File listing from remote to local directory

Thank you. the code works
The Following User Says Thank You to pavan_test For This Useful Post:
methyl (04-17-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FTP files from different directory from remote server to one directory in local dassv Shell Programming and Scripting 3 12-16-2011 10:01 AM
How to execute a remote file with local command Veera_Raghav HP-UX 2 01-16-2009 09:42 AM
Calculate the time difference between a local file and a remote file. meetmano143 Shell Programming and Scripting 1 11-04-2008 01:59 PM
File System - Remote or Local?? Un1xNewb1e UNIX for Dummies Questions & Answers 1 04-11-2008 04:23 PM
[FTP]opying of file from remote to local machine sonbag_pspl Solaris 1 08-12-2004 04:15 AM



All times are GMT -4. The time now is 05:36 AM.