# FPT download today+ filename ! help



## c4danger (Mar 9, 2009)

hi !
i really need help on this ftp script 
I have ftp server and 2 public folders are : new , old
inside have a a lot of files
the format files name is : year month day _data.dat
exp : 20090527_data.dat

D:\test 
D:\test\new
20090527_data.dat
20090528_data.dat
D:\test\old
so any one can help me ! so the ftp script can copy all today files inside folder new from this FTP server to other pc
thx for helping !!!


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!

Are you wanting to download only files with today's date from the New folder to your PC or wanting to copy files with today's date from New to Old?
Is there just one file, or multiple, i.e. 20090310_data.dat, 20090310_data1.dat, or 2009-0310_randomname.dat?

Jerry


----------



## c4danger (Mar 9, 2009)

yes ! all files in my folder are same format day_data.dat 
(exp 20090317_data.dat
20090417_data.dat
20090529_data.dat)

exp if today is march 17 2009 so i have file 20090317_data.dat
and i want to download only today file from FTP server to my pc 

so anyway to do that with FTP 
or can be FTP + batch script ?
thx


----------



## TheOutcaste (Aug 8, 2007)

The following will do that.
I've zipped the file and attached it as well. If you copy this code from the forum, the red line will need to be edited, so might be easier to download the attachment. You can name it anything you want. You'll need to edit the lines in blue to put in your info.
*_ftpscr* is the Folder name on the FTP folder that contains the files, which you've said is *New*. This is case sensitive.
*_Local *is the path to the folder on your PC that you want the files downloaded into.

There is a security issue here, as the username and password for the FTP server is stored in the file, so anyone who can read this file will have access to that info, so best to keep it in your UserProfile, say the My Documents folder, or on your Desktop.
Computer Administrators can always access your User Files if they want. If that's a problem, it's easy enough to modify so that it will either prompt for the password (and username if desired) or so that they must be entered on the command line when you run the file.
Also, if an error occurs, or the script is stopped with CTRL+C, the temp file that is created in the temp folder might not get deleted, and the password will be in this file in plain text.
This is the standard Windows XP temp folder for the currently logged on user:
*C:\Documents and Settings\Username\Local Settings\Temp*
So if an error occurs, you may want to check this folder and delete the *ftp.tmp* file. It can be opened easily from *Start | Run*, type *%temp%*, press Enter. This will also open the temp folder in Vista


```
@Echo Off
[COLOR=Red]:: The following line is a TAB followed by a space
:: If you copy this off the web, you must manually edit this line.
Set _Tab=     [/COLOR]
Set _scr1=[COLOR=Magenta]%temp%\ftp.tmp[/COLOR]
[COLOR=Blue]Set _FTPServer="ftp address"
Set _un="username"
Set _pass="password"
Set _ftpscr=New
Set _Local=C:\Downloads[/COLOR]
Call :_GetDate
If NOT EXIST %_Local% mkdir %_Local%
 >"%_scr1%" Echo open %_FTPServer%
>>"%_scr1%" Echo %_un%
>>"%_scr1%" Echo %_pass%
>>"%_scr1%" Echo lcd %_Local%
>>"%_scr1%" Echo cd %_ftpscr%
>>"%_scr1%" Echo binary
>>"%_scr1%" Echo mget %_fdate%_data.dat
>>"%_scr1%" Echo quit
ftp -i -s:"%_scr1%"
Del "%_scr1%"
Goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::                    Subroutines
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:_GetDate
:: This batch file will always display the same results,
:: independent of "International" settings.
:: This batch file uses REG.EXE from the NT Resource Kit
:: (already installed with WinXP and Vista)
:: to read the "International" settings from the registry.
:: Date is returned as yyyymmdd in variable _fdate
:: Modified by The Outcaste from SortDate Written by Rob van der Woude
:: http://www.robvanderwoude.com
::
For /F "TOKENS=1* DELIMS= " %%A In ("%date%") Do Set _DATE=%%B
:: Delims is a TAB followed by a space
For /F "TOKENS=2* DELIMS=%_Tab%" %%A In ('REG QUERY "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B
For /F "TOKENS=2* DELIMS=%_Tab%" %%A In ('REG QUERY "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B
IF [%_DATE%]==[] (
    IF %_iDate%==0 For /F "TOKENS=1-3* DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%B%%C
    IF %_iDate%==1 For /F "TOKENS=1-3* DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%C%%B
    IF %_iDate%==2 For /F "TOKENS=1-3* DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%B%%C%%D
  ) ELSE (
    IF %_iDate%==0 For /F "TOKENS=1-4* DELIMS=%_sDate% " %%A In ("%date%") Do Set _fdate=%%D%%B%%C
    IF %_iDate%==1 For /F "TOKENS=1-4* DELIMS=%_sDate% " %%A In ("%date%") Do Set _fdate=%%D%%C%%B
    IF %_iDate%==2 For /F "TOKENS=1-4* DELIMS=%_sDate% " %%A In ("%date%") Do Set _fdate=%%B%%C%%D
  )
Goto:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
```
HTH

Jerry


----------



## c4danger (Mar 9, 2009)

so cool !! Thx so much


----------

