Solved

Automate FTP logon test

Posted on 2004-09-29
4
646 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

21 Experts available now in Live!

Get 1:1 Help Now