Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie needs BIG help! :)

Status
Not open for further replies.

DigitalXXL

Technical User
Nov 11, 2003
3
DE
Hi Guys!

I´ve just started learning tcl a few days ago. I allready understand the basics and also wrote a few small scripts. But now I have an idea of a script I really want to write, but I don´t know how.
Okay, so here´s the idea:
It should run on an Eggdrop. It should check 2 or 3 ftp´s if they´re up or down and should put the result of the check into the topic of the chan. BUT!!! It´s not enough to just ping them. The script should login with a login and a password. Is that somehow possible?

Would be awesome if someone could help me out!
 
Look at the help page for the "ftp" package in Tcllib. For the "open" command, it says:

::ftp::Open server user passwd ?options?
This command is used to start a FTP session by establishing a control connection to the FTP server. The defaults are used for any option not specified by the caller.

The command takes a host name server, a user name user and a password password as its parameters and returns a session handle that is an integer number greater than or equal to "0", if the connection is successfully established. Otherwise it returns "-1". The server parameter must be the name or internet address (in dotted decimal notation) of the ftp server to connect to. The user and passwd parameters must contain a valid user name and password to complete the login process.

This should be just the ticket for your problem.

Bob Rashkin
rrashkin@csc.com
 
First of all, thanks a lot for your answer!
But there a still a lot of ??? around my head! :)

Could you maybe give me an example of the code? Like a said, I´m pretty new to this. All I´ve learned yet is from some web tutorials...
 
Sure.

First you'll want to access the ftp package:
package require ftp

Then you have to have some way of storing the ftp site addresses and associated userid and password. I think I would do it with a list:

set biglist {xx.xx.xx.xx user1 pw1 xx.xx.xx.xx user2 pw2...}

Then you'll want to step through the list, 3 at a time:

foreach {addr uid pwd} $biglist {
set statval [::ftp::Open $addr $uid $pwd]
if {$statval<0} {
<do whatever if the site is down>
} else {
<do whatever if the site is up>
::ftp::Close $statval;# to close the connection after
}
}

Does that make sense?


Bob Rashkin
rrashkin@csc.com
 
Looks very promising! :)
But like every noobie I still have some questions...
Is it possible to specify the ports of the ftps, because they´re not running on port 21. And second question, how should I start this script? Is it possible to use something like a timer? Like checking once a hour if the ftps are up or down?

Thank you so much for your help!
 
Yes, it's possible to specify the port:

::ftp::Open server user passwd -port <portnumber>

At this juncture, it seems you don't know about the very useful help file that comes with the ActiveState download. In truth, most of what I know about Tcl, I got from the help files and the demo examples. You should check it out.

As for running the script periodically, you can do that with a timer and have the the script running all the time.
The timer command in Tcl is &quot;after <#ofmsecs>&quot;. Alternatively you can use something like &quot;cron&quot; or &quot;at&quot; to have the OS launch the (one shot) script every once in a while.


Bob Rashkin
rrashkin@csc.com
 
to run a timed script:

Unix: cron

windoze: at (also winat)

both are schedulers

if your program needs to run as a service under windoze, look at &quot;svrany&quot;, which is a generalized generic service manager for EXE programs (you have to use prowrap to get an exe). If the program dies for some reason, svrany will go &quot;not responding&quot; on the process stack for task manager. When this happens, the service manager will attempt to relaunch your program. This is only if you need your program to be a &quot;daemon&quot; under windows, otherwise the above schedulers should work for you.

hope this helps


John Lopez
Enterprise PDM Architect
lopez.john@goodrich.com
 
i recommend getting a copy of 'tcl/tk in a nutshell'. it is a really good tcl/tk handbook it always gives me all the details i need about tcl and tk commands. it also covers tclx, expect and several other extensions.

[tt]
Breadcrust (aka J@red)

Web - E-mail - net-head@softhome.net
Linux Reg. Number - 307180 ([/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top