?
Solved

Automate FTP logon test

Posted on 2004-09-29
4
Medium Priority
?
686 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

801 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