Move from FTP and count in Target folder automated

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#136 Post by aaksar » 12 Dec 2012 03:53

By the code which you have given earlier

Code: Select all

For /F "delims=" %%a in ('Type "%~1"') Do (
   For /F "delims=" %%b in ('Type "%temp%\%~8\server_list.lst"') Do (
   Set "SFname=%%~nb"
   Set "SFext=%%~xb"
   setlocal enabledelayedexpansion
      IF "%%a"=="!SFname:~0,-9!!SFext!" (
         IF NOT EXIST "%~6\%%b" echo get %%b>>"%temp%\%~8\commands_2.ftp"
      )
   endlocal
   )
)


its removing the last 8 char whether its date or not
so without date files are not copied

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#137 Post by abc0502 » 12 Dec 2012 04:12

In this code, I'm assuming that the year is in the date is related to the current year.
In this one, it will get the year from your PC (if the year was set wrong for any reason in your pc it won't work) and for each file name in the server_list.lst it will check to see if the year exist in it's name "2nd last 4 digits" if so it will remove the date and compare the name only, if not exist the year it will just compare the name as it is.

Edited the missing get word

Code: Select all

:: Get Current Year
Setlocal EnableDelayedExpansion
For /F "tokens=2 delims= " %%A in ('echo %date%') Do (
   Set "CDate=%%A"
   Set "year=!CDate:~6,4!"
   )

For /F "delims=" %%A in ('Type "%~1"') Do (
   For /F "delims=" %%a in ('Type "%temp%\%~8\server_list.lst"') Do (
      Set "SFname=%%~na"
      Set "SFDate=!SFname:~-8!"
      Set "SFYear=!SFDate:~0,4!"
      Set "SFext=%%~xa"
      :: Check if file has date at the end or not
      IF "!SFYear!" EQU "%year%" (
         setlocal enabledelayedexpansion
            IF "%%A"=="!SFname:~0,-9!!SFext!" (
               IF NOT EXIST "%%a" echo get %%a>>"%temp%\%~8\commands_2.ftp" )
         endlocal
      ) Else (
         setlocal enabledelayedexpansion
            IF "%%A"=="!SFname!!SFext!" (
               IF NOT EXIST "%%a" echo get %%a>>"%temp%\%~8\commands_2.ftp" )
         endlocal )
   )
)

This is a new code with differant %%A and %%b, just copy and replace the old with this one
Last edited by abc0502 on 13 Dec 2012 08:19, edited 1 time in total.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#138 Post by aaksar » 12 Dec 2012 07:28

so that means , it relate Year from my System date.

so next year also i dont need to change the code right coz its picking from system?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#139 Post by abc0502 » 12 Dec 2012 11:31

yes that's right, i was going to make you set that up in the FTP.set but that was going to change every thing or make it hard coded in that code and you might forget to change it so this won't need any changes from you it just will work automatically.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#140 Post by aaksar » 13 Dec 2012 02:02

Its working fine... I think you forgot to add the get command in script
i added.

Code: Select all

For /F "delims=" %%A in ('Type "%~1"') Do (
   For /F "delims=" %%a in ('Type "%temp%\%~8\server_list.lst"') Do (
      Set "SFname=%%~na"
      Set "SFDate=!SFname:~-8!"
      Set "SFYear=!SFDate:~0,4!"
      Set "SFext=%%~xa"
      :: Check if file has date at the end or not
      IF "!SFYear!" EQU "%year%" (
         setlocal enabledelayedexpansion
            IF "%%A"=="!SFname:~0,-9!!SFext!" (
               IF NOT EXIST "%%a" echo [color=#800040]get[/color] %%a>>"%temp%\%~8\commands_2.ftp" )
         endlocal
      ) Else (
         setlocal enabledelayedexpansion
            IF "%%A"=="!SFname!!SFext!" (
               IF NOT EXIST "%%a" echo [color=#800040]get[/color] %%a>>"%temp%\%~8\commands_2.ftp" )
         endlocal )
   )
)

but when I dont have zip file it gives error

Code: Select all

Error:
there is no such archive
Could Not Find C:\Users\service_infa\Desktop\12345\*.zip


i have changed the code also

Code: Select all

IF "%Fcount%" EQU "%~5" (
   "%zip_program%" x -y "%~6\*.%zipped%" -o"%~6" 2>nul
   Del /F /Q "%~6\*.%zipped%" 2>nul


and can it create the error.log so any error we can go and check in error .log file.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#141 Post by abc0502 » 13 Dec 2012 08:18

i'm not sure but if you mean errors when unzipping the archive files, try make this code like that

Code: Select all

"%zip_program%" x -y "%~6\*.%zipped%" -o"%~6" 2>"%~6\log.log"

this should redirect the errors to log.log files, "%~6" will create the log file in the output location where the files are being extracted to.

but if any other errors that i think will be difficult as there is too many commands

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#142 Post by aaksar » 13 Dec 2012 09:20

actually i was talking abt overall error,

so after every command i put

Code: Select all

>"%~6\log.log
so all the output will redirect to this log file right?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#143 Post by abc0502 » 14 Dec 2012 01:59

as i said it will be more difficult as it will just log every thing and maybe in some commands it will take these commands and log it in the log file instead of executing them.

any way any errors that might happen will be one of these:
> you forgot to add the file name to be downloaded. "in FILE.lst1"
> a new format of a file name. "in FILE.lst1"
> wrong settings like " wrong username or password ..etc," "in FTP.set"
as the batch take it's inputs from external files you set.

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#144 Post by aaksar » 20 Dec 2012 07:05

ok got ur point.

can it be possible to create 0 byte file once my 1 ftp is complete, like in my FTP.set file there are 2 entries
1st entry copied 8 files and 2nd entry copied 5 files

so once my 1st entry 8 files copied then it create 0 byte file in my desired location and when 2nd done then also create 0 byte file,

that will help me to start my process , i can check whether 0 byte file is created or not, once created i start my process.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Move from FTP and count in Target folder automated

#145 Post by Squashman » 20 Dec 2012 07:22

Code: Select all

type nul>Zerobyte.txt

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#146 Post by aaksar » 20 Dec 2012 08:50

But i need to create once all the file copied
. From one ftp location.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Move from FTP and count in Target folder automated

#147 Post by Squashman » 20 Dec 2012 09:06

aaksar wrote:But i need to create once all the file copied
. From one ftp location.

Do you understand how your current batch file works?

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#148 Post by aaksar » 20 Dec 2012 23:04

ok, I have done this.

ABC0502: I have given 2 ftp location, my target folder is same.

so in both ftp location copying 2-2 files.

so after copying the files it should come out from looping, but its not coming out , and in target folder it should have 4 files , and it has 4 files.

if its counting on target folder , then it should come out.

Code: Select all

:: Check Condition to Exit or Continue Looping
Echo Check count number
Setlocal EnableDelayedExpansion
IF "%Fcount%" EQU "%~5" (
    type nul>"%~6"\Zerobyte.txt
   "%zip_program%" x -y "%~6\*.%zipped%" -o"%~6" 2>nul
   Del /F /Q "%~6\*.%zipped%" 2>nul
   RMDIR /S /Q "%temp%\%~8" >nul
   Goto :EOF

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Move from FTP and count in Target folder automated

#149 Post by abc0502 » 22 Dec 2012 08:24

The counting should work fine, i tested before with 2 and up to 5 files and it was always work fine, so it could be something wrong in your system like the one that require you to provide the full path to all files,
any way try these:

Edited
add ping localhost -n 3 >nul
before this lines :
ping localhost -n 3 >nul
:: Check files count
::Echo Counting files in local folder
set Fcount=0
For /F "delims=" %%a in ('Dir /B "%~6\*.*"') Do set /a Fcount += 1
to give few seconds for the files to be created and counted

and change this block of code:

Code: Select all

:: Check Condition to Exit or Continue Looping
::Echo Check count number
Setlocal EnableDelayedExpansion
IF "%Fcount%" EQU "%~5" (
   type nul>"%~6\Zerobyte.txt"
   "%zip_program%" x -y "%~6\*.%zipped%" -o"%~6" >nul
   Del /F /Q "%~6\*.%zipped%" >nul
   RMDIR /S /Q "%temp%\%~8" >nul
   Goto :EOF
) Else (
   Del /F /Q "%temp%\%~8\server_list.lst" >nul
   :: Wait 5 min
   Ping Localhost -l 1 -n 300 >nul
   Goto :loop )

to this:

Code: Select all

:: Check Condition to Exit or Continue Looping
::Echo Check count number
Setlocal EnableDelayedExpansion
IF "%Fcount%" EQU "%~5" (
   type nul>"%~6\Zerobyte.txt"
   "%zip_program%" x -y "%~6\*.%zipped%" -o"%~6" >nul
   Del /F /Q "%~6\*.%zipped%" >nul
   RMDIR /S /Q "%temp%\%~8" >nul
   Goto :EOF
)
Del /F /Q "%temp%\%~8\server_list.lst" >nul
:: Wait 5 min
Ping Localhost -l 1 -n 300 >nul
Goto :loop

maybe the if statement doesn't work for you

aaksar
Posts: 105
Joined: 17 Nov 2012 05:13

Re: Move from FTP and count in Target folder automated

#150 Post by aaksar » 22 Dec 2012 09:40

Actually my target folder is same and in ftp.set file i hv made 2 entry and give different remote folder,.


So all the given files copied to the target location from both entry, but the batch didnt come out. It was still looping.

Actually i wanted to test if i give more than 1 entry in ftp.set file. So after copying all the files from each location it will create seperate zero byte file or not.
As i need to create zero byte file after each entry in ftp.set file is completed

Post Reply