Solved

Automate FTP logon test

Posted on 2004-09-29
4
656 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
  • 2
  • 2
4 Comments
 
LVL 95

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 95

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now