script to DL newest file in directory

Questions about programming languages and debugging
Post Reply
User avatar
Kirk
suck-o enforcer
suck-o enforcer
Posts: 547
Joined: 25 Apr 2009, 16:00
14
Contact:

script to DL newest file in directory

Post by Kirk »

Does anyone have a quick script i can use to download the newest file in an FTP directly to a local server? each day we get a file similar to this: Enertia_backup_201303170005.bak with the numbers changing to match the date. I need something that will check for the most current date and download it.

thanks
kirk

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: script to DL newest file in directory

Post by bad_brain »

is the local server a Linux or a Windows one?
Image

User avatar
Kirk
suck-o enforcer
suck-o enforcer
Posts: 547
Joined: 25 Apr 2009, 16:00
14
Contact:

Re: script to DL newest file in directory

Post by Kirk »

sorry about that. everything here is windows.

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: script to DL newest file in directory

Post by bad_brain »

damn...would have been really easy with Linux.
Image

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: script to DL newest file in directory

Post by bad_brain »

have a look here, might be a good start:
http://superuser.com/questions/52440/ft ... duled-task" onclick="window.open(this.href);return false;

I am not sure though if/how you can utilize timestamps in windows to fetch only the latest file... :-k
Image

User avatar
Kirk
suck-o enforcer
suck-o enforcer
Posts: 547
Joined: 25 Apr 2009, 16:00
14
Contact:

Re: script to DL newest file in directory

Post by Kirk »

my problem is having the script find a different file name than last time. I was hoping someone new of some date loop i could use. where the script just loops through and checks the date in the file name. I even thought about trying to assign different vars to section of the file name var1=enertia_backup_ var2=2012_ var3=03, etc. then do something with it. just not sure what.

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Re: script to DL newest file in directory

Post by bad_brain »

hm, my batch coding is more than rusty, but have a look at the dir command, from what I have seen you can fetch/list/sort the files by timestamp:
http://www.computerhope.com/dirhlp.htm" onclick="window.open(this.href);return false;

when you managed it to display the last written file for example with the dir command simply pass the name into a variable and then pass it to the ftp command in the script of the last link.... :-k
Image

Post Reply