Solved

Automate FTP logon test

Posted on 2004-09-29
4
684 Views
Last Modified: 2012-05-05
I want to create a simple batch file that can confirm an FTP server can be logged in to:

ie:

ftp -s:c:\temp\test.ftp

where test.ftp =

open ftp.domain.com
user
password
ls
quit

The results output 230 on success, and 530 on failure.  There's no errorlevel, however.

How can I run this and have it parse the results out?

0
Comment
Question by:nummagumma2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 96

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 12183381
ftp -s script.ftp > %temp%\ftp.log 2>&1
find /i "530" %temp%\ftp.log
If "%errorlevel%" == "1" Echo Connect Failed.
0
 
LVL 1

Author Comment

by:nummagumma2
ID: 12185292
Good logic - but the errorlevel string was backwards... =)

ftp -s:c:\temp\test.ftp > %temp%\ftp.log 2>&1
find /i "530" %temp%\ftp.log
If "%errorlevel%" == "0" (
      Echo Connect Failed.
      ) else (
      Echo Connect Succeeded.)


Out of curiosity, what does the 2>&1 do?  It worked fine with it omitted, too.
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 12187177
If errorlevel = 0 then nothing is wrong - no error.  I don't think my logic was backward.

1 = standard output
2 = standard error

> = default redirect standard output
1> = same as >

2> = redirect standard error
2>&1 = redirect standard error to the same file as standard output.

Thus:

... > file.txt 2>&1

redirects both standard output and standard error to the same file, file.txt.  Otherwise, you might miss some details.

Try this for an illustration of how it works:

at a command prompt, type "net /? > file.txt"  Instead of the help info being saved to file.txt, it is displayed.  So the redirection doesn't seem to work.  Then execute the same command like this:  "net /? 2> file.txt" and you'll find the info is now sent to the file.txt
0
 
LVL 1

Author Comment

by:nummagumma2
ID: 12212775
The logic was only 'backwards' in that the "find" command returned a 0 when it found 530, therefore indicating that it was successful.

Thanks for the explanation of the rest.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question