Connecting Tech Pros Worldwide Help | Site Map

FTP a dynamic file with year and month

  #1  
Old February 12th, 2008, 07:09 PM
Newbie
 
Join Date: Feb 2008
Posts: 6
Do somebody know how to come up with a dynamic file name when ftp it ? I need to download a monthly updated file. The file name appears like datafile_yyyymm.zip where yyyy mean year 2008, and mm mean month 02.
  #2  
Old February 13th, 2008, 01:35 AM
Nepomuk's Avatar
Moderator
 
Join Date: Aug 2007
Location: Germany
Posts: 2,468

re: FTP a dynamic file with year and month


Quote:
Originally Posted by yfguo
Does somebody know how to come up with a dynamic file name when ftp it ? I need to download a monthly updated file. The file name appears like datafile_yyyymm.zip where yyyy mean year 2008, and mm mean month 02.
Wait, do I understand correctly, you want to download a file once a month, which is called datafile_yyyymm.zip from an FTP-server? And I guess, this should happen automatically? Sounds to me like a batch-script to me... Any experts on that here?

Greetings,
Nepomuk
  #3  
Old February 13th, 2008, 11:30 AM
harshadd's Avatar
Familiar Sight
 
Join Date: Dec 2007
Posts: 177

re: FTP a dynamic file with year and month


NO matter he wants to upload or download a file.
Ddefinetly he wants a dynamic file name to be get created which he can create using my 7 lines below. and set as an DOS environment variable.
copy these three lines in ur .bat or .cmd file. (save as harshad.bat)
note:-
Date command is passed in this bat file to get current system date.
It requires an input from user on console.which is redirected using "<" to an empty file named "enter"

bat/cmd file is as below: harshad.bat

@ECHO OFF
for /f "usebackq delims=/ tokens=3" %%x IN (`date`) do set YYYY=%%x
for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set MM=%%x
SET FILENAME=DATAFILE_
FOR %%Y IN (%YYYY%) DO SET FILENAME=%FILENAME%%%Y
FOR %%Z IN (%MM%) DO SET FILENAME=%FILENAME%%%Z.ZIP
echo %FILENAME%

to create an emptyfile named "enter" do this on DOS prompt
copy con enter
then press enter key one time to store Carrage Return in the file named "enter"
then press F6 to save file.

when u execute ececute it like this
harshad <enter
and u will have an envirnment variable filename set to your required filename
type SET and check this
tested on XP PRO SP 2

I BET I AM THE MOST POWERFULL MSDOS USER IN ENTIRE MUMBAI ANY ONE WANTs TO CHALLANGE THIS STATEMENT?

HARSHAD.
  #4  
Old February 13th, 2008, 07:38 PM
Newbie
 
Join Date: Feb 2008
Posts: 6

re: FTP a dynamic file with year and month


thank your reply. I think that works.

Here another question rises due my further investigation on not only downloading a file through ftp, but also through http. do you have any idea how to use NT commands to download a file from a web like http://www.mydomain.com/data/datafile.zip ?

Thanks in advance.
  #5  
Old February 15th, 2008, 10:50 AM
harshadd's Avatar
Familiar Sight
 
Join Date: Dec 2007
Posts: 177

re: FTP a dynamic file with year and month


Quote:
Originally Posted by yfguo
thank your reply. I think that works.

Here another question rises due my further investigation on not only downloading a file through ftp, but also through http. do you have any idea how to use NT commands to download a file from a web like http://www.mydomain.com/data/datafile.zip ?

Thanks in advance.
If you know the perfect URL of the file , asuming that the only file name will change daily. you can directly put this URL on browser to get the file d/loaded.
optionally u can make VB/VBS script for this... HND
  #6  
Old February 18th, 2008, 11:51 AM
Nepomuk's Avatar
Moderator
 
Join Date: Aug 2007
Location: Germany
Posts: 2,468

re: FTP a dynamic file with year and month


Quote:
Originally Posted by yfguo
thank your reply. I think that works.

Here another question rises due my further investigation on not only downloading a file through ftp, but also through http. do you have any idea how to use NT commands to download a file from a web like http://www.mydomain.com/data/datafile.zip ?

Thanks in advance.
To download a file from command line, you can use a program like wget, which originally comes from the *nix area, but was ported to Windows.

You just have to use the command
Expand|Select|Wrap|Line Numbers
  1. wget "http://www.mydomain.com/data/datafile.zip"
to download it.
By the way, wget supports both ftp and http downloads.

Greetings,
Nepomuk
  #7  
Old March 31st, 2008, 08:50 AM
Newbie
 
Join Date: Mar 2008
Posts: 1

re: FTP a dynamic file with year and month


Quote:
Originally Posted by harshadd
NO matter he wants to upload or download a file.
Ddefinetly he wants a dynamic file name to be get created which he can create using my 7 lines below. and set as an DOS environment variable.
copy these three lines in ur .bat or .cmd file. (save as harshad.bat)
note:-
Date command is passed in this bat file to get current system date.
It requires an input from user on console.which is redirected using "<" to an empty file named "enter"

bat/cmd file is as below: harshad.bat

@ECHO OFF
for /f "usebackq delims=/ tokens=3" %%x IN (`date`) do set YYYY=%%x
for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set MM=%%x
SET FILENAME=DATAFILE_
FOR %%Y IN (%YYYY%) DO SET FILENAME=%FILENAME%%%Y
FOR %%Z IN (%MM%) DO SET FILENAME=%FILENAME%%%Z.ZIP
echo %FILENAME%

to create an emptyfile named "enter" do this on DOS prompt
copy con enter
then press enter key one time to store Carrage Return in the file named "enter"
then press F6 to save file.

when u execute ececute it like this
harshad <enter
and u will have an envirnment variable filename set to your required filename
type SET and check this
tested on XP PRO SP 2

I BET I AM THE MOST POWERFULL MSDOS USER IN ENTIRE MUMBAI ANY ONE WANTs TO CHALLANGE THIS STATEMENT?

HARSHAD.

Thanx harshadd, but can you show me how to fetch a dynamic file name like "datafile_ddmmyy.csv" from an ftp location like "ftp://location/folder/datafile_ddmmyy.csv" and save it as "datafile.csv" in the location of the bat script?
  #8  
Old March 31st, 2008, 10:06 AM
harshadd's Avatar
Familiar Sight
 
Join Date: Dec 2007
Posts: 177

re: FTP a dynamic file with year and month


Quote:
Originally Posted by shanaf
Thanx harshadd, but can you show me how to fetch a dynamic file name like "datafile_ddmmyy.csv" from an ftp location like "ftp://location/folder/datafile_ddmmyy.csv" and save it as "datafile.csv" in the location of the bat script?
Date command from DOS returns o/p like this
C:\>date
The current date is: 31/03/2008
Enter the new date: (dd-mm-yy)
here Year is in YYYY format.
You required in YY format.. its posible but not easy task to get it converted into YY.
Please feedle with FOR command and try to get only 2 digit year as output

FOR /f "usebackq delims=/ tokens=3" %x IN (`date`) do echo %x
Also getting Date is too NOT simple as above commands can give you year(YYYY)
and Month (MM) by changing tokens=2
But tokens=1 do not give date in (DD) form


wait... let me try........
  #9  
Old April 1st, 2008, 12:45 PM
harshadd's Avatar
Familiar Sight
 
Join Date: Dec 2007
Posts: 177

re: FTP a dynamic file with year and month


To get filename dinamically as datafile_ddmmyy.csv use the below .BAT file.
note you have to have your regional setting for this bat file to work properly as
CUSTOM date "/dd/MM/yyy" instead of "dd/MM/yyyy" .
Note that MM is in caps and and an extra "/" is required to work with this bat file.
This is only because I can not resolve Date part of date if date is not starting with "/" Month and year can be resolved as u seen earlier....
Regards HArshad.

///start harshad.bat
@ECHO OFF
for /f "usebackq delims=/ tokens=3" %%x IN (`date`) do set YYYY=%%x
for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set MM=%%x
for /f "usebackq delims=/ tokens=2" %%x IN (`date`) do set DD=%%x

SET FILENAME=DATAFILE_
FOR %%Y IN (%YYYY%) DO SET FILENAME=%FILENAME%%%Y
FOR %%Z IN (%MM%) DO SET FILENAME=%FILENAME%%%Z
FOR %%X IN (%DD%) DO SET FILENAME=%FILENAME%%%X.csv

echo %FILENAME%
//end harshad.bat

I am working on this to happend without changing regional settings or to change it and reset back onthe fly.
Regards
Harshad
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 14th, 2005 04:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM