FOR Loop FTP Test

Microsoft / Dos 6.22
October 21, 2009 at 07:45:36
Specs: Windows XP
The batch file is supposed to read each line as
input variables, and test an ftp connection.
It seems to work for the first user, but then
gets stuck at the ftp> prompt. I want to loop
through ~200 users to validate the accounts. I
also wan't to capture all output to test if the
user is valid.

ftp.users.txt file layout: username,password

test.ftp.cmd
-----------------
@echo off
setLocal EnableDelayedExpansion
for /f "tokens=1,2 delims=, " %%a in (ftp.users.txt) do (
echo %%a
echo %%b
ftp
open 10.10.10.1
%%a
%%b
pwd
disconnect
bye
)
-----------------


See More: FOR Loop FTP Test

Report •


#1
October 21, 2009 at 08:36:24
Only the following commands are being executed:

echo %%a
echo %%b
ftp

At this point, you are in the FTP shell and batch file execution is suspended until you exit the FTP shell. You can see this if you type "bye" and hit enter. When you do, you exit the FTP shell and the batch file resumes. You see error messages for the remaining commands in the loop because they're FTP commands and you're no longer at the FTP command line. Then, the second user is processed and you're dumped at the FTP command line again. And so on... until the entire input file has been processed.

It's been a long time since I've done this, but you need to create an FTP script and specify the script file when you launch the FTP command like this: ftp /s:scriptname.scr

Instructions can be found here:
http://support.microsoft.com/kb/96269

I'm sure the good folks in the programming forum could provide more detailed assistance if you need it.

-- kptech


Report •

#2
October 21, 2009 at 10:26:20
doht! duh...
I made some changes to echo data into a ftpuser.txt file, so I
can call the -s ftp option. However, this doesn't seem to work
all the darn time... not sure why.

New script:
----------------
@echo off
setLocal EnableDelayedExpansion
for /f "tokens=1,2 delims=, " %%a in (ftp.users.txt) do (
echo username: %%a
echo password: %%b
echo %%a > ftpuser.txt
echo %%b >> ftpuser.txt
echo bye >> ftpuser.txt
ftp -s:ftpuser.txt 10.10.10.1
)


Report •

#3
October 21, 2009 at 10:37:51
OK, this is becoming painful...
I have noticed that in my ftp.users.txt file (input file) that many of
the passwords have a ! in the password, and this does not echo
into the -s file ftpuser.txt... dang! Futhermore, the echo is
putting a space on the password, so all passwords are failing.
ugh.

Report •

Related Solutions

#4
October 21, 2009 at 11:14:08
@echo off

for /f "tokens=1-2 delims=," %%a in (userlist) do (
call :sub1 %%a %%b
)
goto :eof

:sub1
@echo off > #

>> # echo o 10.10.10.1
>> # echo %1
>> # echo %2
>> # echo bye

ftp -s:#

goto :eof


=====================================
Helping others achieve escape felicity

M2


Report •

#5
October 21, 2009 at 14:09:10
Well that is just too beautiful~!
It worked like a charm.
This was my last code and issues until your RE:.
Thank you so much.
---
rem @echo off
for /f "tokens=1,2 delims=," %%a in (ftp.users.txt) do (
set ftpuser=
set pw=
set ftpuser=%ftpuser%%%a
set pw=%pw%%%b
set ftpuser=%ftpuser: =%
set pw=%pw: =%
echo %ftpuser%
echo %pw%
echo %%a > ftpuser.txt
echo %%b >> ftpuser.txt
echo pwd >> ftpuser.txt
echo bye >> ftpuser.txt
ftp -s:ftpuser.txt 10.10.10.1
)
---
I have two issues when I echo the variables(default tokens or
set variables) into ftpuser.txt.
1. The variables add a trailing space. This causes the ftp –
s user and password input to fail. I need to trim the trailing
space. I’ve tried a few things, and left the set command stuff
that is supposed to work, but it’s wiping the variable data.
2. The ! character is stripped. Many passwords have a ! in
them.

Once I’m done verifying all accounts, I plan to wipe out the DR
ftp configuration, and rebuild the users, FTP virtual sites, and
NTFS folders automatically via scripts.
I’m off to code in VBscript…


Report •

#6
October 21, 2009 at 14:22:08
echo %%a >

gives you a space because there's a space after %%a.

I have no idea what you're doing with all those SETs


=====================================
Helping others achieve escape felicity

M2


Report •


Ask Question