Help with batch file...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jmjaneiro
Posts: 1
Joined: 04 Jun 2010 23:40

Help with batch file...

#1 Post by jmjaneiro » 05 Jun 2010 00:10

Hi all,

I'm trying to automatize a task that consists on downloding every day some files from a ftp site.
I'm having a problem with my batch file and I ran out of ideas for trying to solve this.
My batch is like this:

@echo off&SETLOCAL

cd /D D:\FTP files\PCOMS
md %date%
cd %date%

FOR /f "tokens=1-4 delims=/-. " %%G IN ('date /t') DO (call :s_fixdate %%G %%H %%I %%J)
goto :s_print_the_date

:s_fixdate
if "%1:~0,1%" GTR "9" shift
FOR /f "skip=1 tokens=2-4 delims=(-)" %%G IN ('echo.^|date') DO (
set %%G=%1&set %%H=%2&set %%I=%3)
goto :eof

:s_print_the_date
echo Month:[%mm%] Day:[%dd%] Year:[%yy%]
ENDLOCAL&SET mm=%mm%&SET dd=%dd%&SET yy=%yy%

echo user> FTP.txt
echo pass>> FTP.txt

echo cd directory1 >> FTP.txt
echo asc >> FTP.txt
echo hash >> FTP.txt
echo prompt >> FTP.txt

echo mget file1.hdf5 >> FTP.txt
echo mget file2.hdf5 >> FTP.txt
echo mget file3.hdf5 >> FTP.txt
echo mget file4.hdf5 >> FTP.txt

echo cd ../directory2 >> FTP.txt
echo asc >> FTP.txt
echo hash >> FTP.txt
echo prompt >> FTP.txt

echo mget %yy%%mm%%dd%.000000.hdf5 >> FTP.txt

echo bye >> FTP.txt
echo quit >> FTP.txt

call FTP.bat


FTP.bat just calls the ftp command:

ftp -d -s:FTP.txt -w:33000000 ftp.site.com > ftplog.txt

I run this and I just get:

Month:[06] Day:[05] Year:[]

I wait ages and nothing happens. Can someone give me a hand here please!

Cheers

Joao

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Help with batch file...

#2 Post by amel27 » 05 Jun 2010 06:00

jmjaneiro wrote:if "%1:~0,1%" GTR "9" shift
its not working, variable required:

Code: Select all

Set aa=%~1
If "%aa:~0,1%" GTR "9" Shift

jmjaneiro wrote:I run this and I just get:

Month:[06] Day:[05] Year:[]
try this:

Code: Select all

@Echo Off

CD /D D:\FTP files\PCOMS
If Not Exist "%date%" MD "%date%"
CD "%date%"

For /F "Tokens=1-4 Delims=/-. " %%a IN ("%date%") Do Call :S_FixDate %%a %%b %%c %%d
GoTo :S_Print_The_Date

:S_FixDate
Set aa=%~1
If "%aa:~0,1%" GTR "9" Shift
For /F "Skip=1 Tokens=2-4 delims=(-)" %%i In ('echo.^|date') Do (
Set %%i=%~1& Set %%j=%~2& Set %%k=%~3)
GoTo :EOF

:S_Print_The_Date
Echo Month:[%mm%] Day:[%dd%] Year:[%yy%]

Pause >Nul

P.S. if problem, result of command required:

Code: Select all

echo.|date

SenHu
Posts: 19
Joined: 19 Mar 2009 14:57

Re: Help with batch file...

#3 Post by SenHu » 13 Jun 2010 11:57

Possible alternative. Can also use a script like http://www.biterscripting.com/SS_FTPUpload.html .

Post Reply