Computing.Net > Forums > Windows XP > FOR Loop FTP Test

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

FOR Loop FTP Test

Reply to Message Icon

Name: troyboy14k
Date: October 21, 2009 at 07:45:36 Pacific
OS: Windows XP
Product: Microsoft / Dos 6.22
Subcategory: General
Comment:

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
)
-----------------



Sponsored Link
Ads by Google

Response Number 1
Name: kptech
Date: October 21, 2009 at 08:36:24 Pacific
Reply:

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


1

Response Number 2
Name: troyboy14k
Date: October 21, 2009 at 10:26:20 Pacific
Reply:

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
)


0

Response Number 3
Name: troyboy14k
Date: October 21, 2009 at 10:37:51 Pacific
Reply:

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.


0

Response Number 4
Name: Mechanix2Go
Date: October 21, 2009 at 11:14:08 Pacific
Reply:

@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


1

Response Number 5
Name: troyboy14k
Date: October 21, 2009 at 14:09:10 Pacific
Reply:

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…


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: October 21, 2009 at 14:22:08 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: FOR Loop FTP Test

how to do for loop batch in xp? www.computing.net/answers/windows-xp/how-to-do-for-loop-batch-in-xp/48633.html

pass variables between nested for loops www.computing.net/answers/windows-xp/pass-variables-between-nested-for-loops/180030.html

Multiple do commands in for loop www.computing.net/answers/windows-xp/multiple-do-commands-in-for-loop/168961.html