mIRC Home    About    Download    Register    News    Help

Print Thread
#10585 11/02/03 03:33 AM
Joined: Jan 2003
Posts: 237
X
xrn0id Offline OP
Fjord artisan
OP Offline
Fjord artisan
X
Joined: Jan 2003
Posts: 237
here is my script. What it does is connect to a ftp to see if it is on. But I only have one problem, what will it return if the ftp is not on, or it cant connect? isnt there a socketname for that or something? somebody please help!

Code:
\on *:LOAD:{
  set %::Ftp.Type .notice 
  echo -a Ftp Tester LOADED!!
}
menu menubar,channel,status,nicklist {
  -
  Ftp Tester
  .Result Settings
  ../notice:set %::Ftp.Type .notice 
  ../msg:set %::Ftp.Type .msg 
  -
}

on *:Text:!test*:#:{
  if ($nick == xrn0id) { do.ftp.test $strip($2) | halt }
  if ($nick == l33t) { do.ftp.test $strip($2) | halt }
  halt
}
alias do.ftp.test {
  if (%ftp.stat == No) { %::Ftp.Type $nick Sorry, Please Wait another $timer(cd.ftp.test).secs $+ seconds Before testing again! | halt }
  set %what.ftp $1
  set %ftp.2.test $gt.ftp($1)
  set %ftp.who $nick
  sockopen Ftp $+ $rand(99999,999999999) $gettok(%ftp.2.test,1,32) $gettok(%ftp.2.test,4,32)
  set %ftp.stat No
  .timercd.ftp.test 1 15 ftp.end.session
  %::Ftp.Type %ftp.who Attempting Connection...Timeout is set to 15 Seconds
}
alias gt.ftp {
  var %ss,%l,%p,%ano,%dir,%pu,%s,%n = 1,%ds
  %ss = $remove($1-,ftp://)
  if ($numtok(%ss,64) > 1) {
    %l = $gettok($gettok(%ss,1- [ $+ [ $calc($numtok(%ss,64) - 1) ] ] ,64),1,58)
    %p = $gettok($gettok(%ss,1- [ $+ [ $calc($numtok(%ss,64) - 1) ] ] ,64),2,58)
  }
  if (%l == $null) {
    %l = anonymous
    %ano = 1
  }
  else { %ano = 0 }
  if (%p == $null) { %p = $null }
  %ss = $gettok(%ss,$numtok(%ss,64),64)
  if ($gettok(%ss,2-,47) != $null) {
    %dir = $ifmatch
    if (/* !iswm %dir) { %dir = / $+ %dir }
  }
  %ss = $gettok(%ss,1,47)
  if ($gettok(%ss,2,58)) { %pu = $ifmatch }
  elseif ($gettok(%dir,2,58)) { %pu = $ifmatch }
  else { %pu = 21 }
  %dir = $gettok(%dir,1,58)
  %ss = $gettok(%ss,1,58)
  %s = $gettok($gettok(%ss,1,47),1,32)

  if (%pu !isnum) { %pu = 21 }
  if (%dir == $null) { var %dir }
  while ($sock(ftp [ $+ [ %n ] ] )) { inc %n }
  %ds = FTP $+ %n

  ;Ip: %s User: %l Pass: %p Port: %pu

  return %s %l %p %pu
}
on *:sockopen:ftp*:{
  if ($sockerr) {
    %::Ftp.Type $nick Error: $sockname FTP session: $sockerr
    return
  }
  %::Ftp.Type %ftp.who Connection established, Waiting for Welcome note!
}
on *:sockread:ftp*:{
  if ($sockerr > 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  ;echo -s 12 %temp

  ;-user/pass-
  if ($gettok(%temp,1,32) == 220) { sockwrite -tn $sockname USER $gettok(%ftp.2.test,2,32) | %::Ftp.Type %ftp.who Welcome note Recived, Now Sending Login... }
  if ($gettok(%temp,1,32) == 331) { sockwrite -tn $sockname PASS $gettok(%ftp.2.test,3,32) | %::Ftp.Type %ftp.who Login Sent, Now Sending Pass... }
  ;---

  ;-Errors-
  if ($gettok(%temp,1,32) == 530) { sockclose $sockname | %::Ftp.Type %ftp.who Error: Login or Password Incorrect! | ftp.fin | halt }
  if ($gettok(%temp,1,32) == 421) { sockclose $sockname | %::Ftp.Type %ftp.who Error: The Ftp is Full! | ftp.fin | halt }
  ;---

  ;-connected-
  if ($gettok(%temp,1,32) == 230) { sockclose $sockname | %::Ftp.Type %ftp.who %what.ftp Currently Working! | ftp.fin | halt }
  ;-

  goto nextread
}
alias ftp.end.session {
  ftp.fin
  halt
}
alias ftp.fin {
notice %ftp.who Check Ftp Done.... Awaiting Status....
if ($gettok(%temp,1,32) ==  230) {
  notice %ftp.who FTP Working, you will be voiced shortly
  mode #l33t +v %ftp.who
  goto next
}
if ($gettok(%temp,1,32) ==  421) {
  notice %ftp.who FTP Working, you will be voiced shortly
  mode #l33t +v %ftp.who
  goto next
}
if ($gettok(%temp,1,32) ==  530) {
  notice %ftp.who Login/Password incorrect. Fix this.
  mode #l33t -v %ftp.who
  goto next
}
if ($gettok(%temp,1,32) ==  $null) {
  notice %ftp.who FTP not on, or wrong port set. Please correct this.
  mode #l33t -v %ftp.who
  goto next
}
:next
.timercd.ftp.test Off
unset %ftp.2.test
unset %ftp.who
unset %what.ftp
set %ftp.stat Yes
sockclose ftp*



;Check for Life

if (%life == $null) {
goto getlife
}
#10586 11/02/03 03:48 AM
Joined: Dec 2002
Posts: 103
Vogon poet
Offline
Vogon poet
Joined: Dec 2002
Posts: 103
basically all of the socket events have a $sockerr identifier which is > 0 when there is an error. Hence in all your sock events (most importantly, sockopen and sockread), you should have something like this at the top of each event:

if ($sockerr) {
echo -a Error: $sockerr
return
}

You can also get the textual error message by specifying a property.


Link Copied to Clipboard