Ftp Script Multi account

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Aska
Posts: 1
Joined: 17 Oct 2016 13:40

Ftp Script Multi account

#1 Post by Aska » 17 Oct 2016 14:14

Hello Everybody

first of all sorry for my English, i don't speak english fluently

I need some Help about Ftp Batch script
I have found a nice script on this Dedicated forum, i have update little, and it's works very nice with one account
I Try to update it for multiple account (arround 700)
Below with update version for one account and on second part and update for read a file witth accounts anf and create nested "for"

Thanks in advance, I works on it since few days, but my mixed combination are fales , I try to search with !VAR1!

Code: Select all

@Echo Off
 
REM -- Define File Filter
Set FindStrArgs=/E /C:".XXX"
 
REM -- Variable account
Set VAR1=USERNAME
Set VAR2=PASSWORD
Set FTSITE=ftp.TEST.COM
Set RMFLD=/FOLDER/YEAR
 
REM -- Define Destination folder
Set FLDDST=%SystemDrive%\EXPLOIT\LCFLDEST
if not exist %FLDDST%\nul md %FLDDST%
Set FLDACCNT=%FLDDST%\%VAR1%
if not exist %FLDDST%\%VAR1%\nul md %FLDDST%\%VAR1%
 
REM -- Ftp Script to create List of Files
 
Set "FtpCommand=ls"
Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp"
REM Notepad "%temp%\%~n0.ftp"
 
REM -- Execute Ftp Script, collect File Names
Set "FileList="
For /F "Delims=" %%A In ('"Ftp -v -i -s:"%temp%\%~n0.ftp"|Findstr %FindStrArgs%"') Do (Call Set "FileList=%FileList% "%%A"")
 
REM -- Ftp Script to download files that don't exist in local folder
Set "FtpCommand=mget"
For %%A In (%FileList%) Do If Not Exist "%FLDACCNT%\%%~A" Call Set "FtpCommand=%FtpCommand% "%%~A""
Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp"
REM Notepad "%temp%\%~n0.ftp"
 
 
For %%A In (%FtpCommand%) Do Echo.%%A
 
REM -- Execute Ftp Script, download files
ftp -i -s:"%temp%\%~n0.ftp"
Del "%temp%\%~n0.ftp"
 
)
 
GOTO:EOF
 
 
:extractFileSection StartMark EndMark FileName -- extract a section of file that is defined by a start and end mark
::                  -- [IN]     StartMark - start mark, use '...:S' mark to allow variable substitution
::                  -- [IN,OPT] EndMark   - optional end mark, default is first empty line
::                  -- [IN,OPT] FileName  - optional source file, default is THIS file
SETLOCAL Disabledelayedexpansion
:$created 20080219 :$changed 20100205 :$categories ReadFile
:$source [url=http://www.dostips.com]http://www.dostips.com[/url]
set "bmk=%~1"
set "emk=%~2"
set "src=%~3"
set "bExtr="
set "bSubs="
if "%src%"=="" set src=%~f0&        rem if no source file then assume THIS file
for /f "tokens=1,* delims=]" %%A in ('find /n /v "" "%src%"') do (
    if /i "%%B"=="%emk%" set "bExtr="&set "bSubs="
    if defined bExtr if defined bSubs (call echo.%%B) ELSE (echo.%%B)
    if /i "%%B"=="%bmk%"   set "bExtr=Y"
    if /i "%%B"=="%bmk%:S" set "bExtr=Y"&set "bSubs=Y"
)
EXIT /b
 
 
[Ftp Script 1]:S
!Title Connecting...
open %FTSITE%
%VAR1%
%VAR2%
 
 
!Title Preparing...
cd %RMFLD%
lcd %FLDACCNT%
ascii
hash
 
!Title Processing... %FtpCommand%
%FtpCommand%
 
!Title Disconnecting...
disconnect
bye


what I want to do is to position (line 22-27 & 80 ) , it is a loop that will read a file line by line, the username and password for each account
two loops work well I see accounts increment. Problem is that parameters VAR 1 et VAR2 are lost when script generate the .ftp file
I have try with 2 scripts second called by the first but same issue VAR1 and VAR2 are lost
Somebody can help me please ?


Multi account version script

Code: Select all

@Echo Off
 
REM -- Define File Filter
Set FindStrArgs=/E /C:".XXX"
 
REM -- Define Destination folder
Set FLDDST=%SystemDrive%\EXPLOIT\LCFLDEST
@if not exist %FLDDST%\nul md %FLDDST%
 
 
REM -- Variable account
Set VAR1=USERNAME
Set VAR2=PASSWORD
Set FTSITE=ftp.TEST.COM
Set RMFLD=/FOLDER/YEAR
 
REM -- Define Destination home folder
Set FLDDST=%SystemDrive%\EXPLOIT\LCFLDEST
@if not exist %FLDDST%\nul md %FLDDST%
 
 
[b][color=#FF0000]Set LSTACCT="C:\Exploit\account.txt"
 
FOR /F "tokens=1,2 delims= " %%i in (%LSTACCT%) Do (
   set VAR1=%%i
   set VAR2=%%j[/color][/b]
 
 
Set FLDACCNT=%FLDDST%\%VAR1%
if not exist %FLDDST%\%VAR1%\nul md %FLDDST%\%VAR1%
 
REM -- Ftp Script to create List of Files
 
Set "FtpCommand=ls"
Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp"
REM Notepad "%temp%\%~n0.ftp"
 
REM -- Execute Ftp Script, collect File Names
Set "FileList="
For /F "Delims=" %%A In ('"Ftp -v -i -s:"%temp%\%~n0.ftp"|Findstr %FindStrArgs%"') Do (Call Set "FileList=%FileList% "%%A"")
 
REM -- Ftp Script to download files that don't exist in local folder
Set "FtpCommand=mget"
For %%A In (%FileList%) Do If Not Exist "%FLDACCNT%\%%~A" Call Set "FtpCommand=%FtpCommand% "%%~A""
Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp"
REM Notepad "%temp%\%~n0.ftp"
 
 
For %%A In (%FtpCommand%) Do Echo.%%A
 
REM -- Execute Ftp Script, download files
ftp -i -s:"%temp%\%~n0.ftp"
Del "%temp%\%~n0.ftp"
 
)
[b][color=#FF0000]) [/color][/b]
GOTO:EOF
 
 
:extractFileSection StartMark EndMark FileName -- extract a section of file that is defined by a start and end mark
::                  -- [IN]     StartMark - start mark, use '...:S' mark to allow variable substitution
::                  -- [IN,OPT] EndMark   - optional end mark, default is first empty line
::                  -- [IN,OPT] FileName  - optional source file, default is THIS file
SETLOCAL Disabledelayedexpansion
:$created 20080219 :$changed 20100205 :$categories ReadFile
:$source [url=http://www.dostips.com]http://www.dostips.com[/url]
set "bmk=%~1"
set "emk=%~2"
set "src=%~3"
set "bExtr="
set "bSubs="
if "%src%"=="" set src=%~f0&        rem if no source file then assume THIS file
for /f "tokens=1,* delims=]" %%A in ('find /n /v "" "%src%"') do (
    if /i "%%B"=="%emk%" set "bExtr="&set "bSubs="
    if defined bExtr if defined bSubs (call echo.%%B) ELSE (echo.%%B)
    if /i "%%B"=="%bmk%"   set "bExtr=Y"
    if /i "%%B"=="%bmk%:S" set "bExtr=Y"&set "bSubs=Y"
)
rem fin boucle lst account
[/
EXIT /b
 
 
[Ftp Script 1]:S
!Title Connecting...
open %FTSITE%
%VAR1%
%VAR2%
 
 
!Title Preparing...
cd %RMFLD%
lcd %FLDACCNT%
ascii
hash
 
!Title Processing... %FtpCommand%
%FtpCommand%
 
!Title Disconnecting...
disconnect
bye


This solution works but, i can only download the last file because for each account it's the last files who is write in .ftp file

Code: Select all

Set Filenme=C:\Exploit\account.txt

FOR /F "tokens=1,2 delims= " %%i in (%Filenme%) Do (
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set VAR1=%%i
set VAR2=%%j
call:sub_Prcss_transfert
)


:sub_Prcss_transfer

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Ftp Script Multi account

#2 Post by foxidrive » 20 Oct 2016 03:27

I read your description but I skipped reading your code for now.

You have 700 ftp acounts on a server and you'd like to perform one task using all 700 accounts: is that right?

Post Reply