mIRC Home    About    Download    Register    News    Help

Print Thread
#53710 11/10/03 02:52 PM
Joined: Dec 2002
Posts: 32
J
Jaakko Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Dec 2002
Posts: 32
Hi..I'm trying to make a FTP script. My problem is that upload isn't working assuredly. If I upload TXT files it works good (tried with a 3mb txt file), but when I upload JPGs for example (even small ones) it doesn't work at all most of the time.

My guess is that JPGs have lots of weird chars...maybe $crlf or something and it fails to bread or something. Anyway it gives error msg like this (line is just after the bread) :

* /sockwrite: insufficient parameters (line 39, script1)

Any guesses whats wrong?


Code:
 
on *:sockopen:ftp:{
  FTP user %user
  FTP pass %pass
  FTP TYPE I
}
on *:sockread:ftp:{
  sockread %rdsck
  echo -at 9 + %rdsck
  if ($gettok(%rdsck,1,32) == 150) && (%intention == upload) {
    bread %ftp.file 1 %ftp.packetsize &ftp.data
    sockwrite ftp.data $bvar(&ftp.data,1,$bvar(&ftp.data,0)).text
  }
  if ($gettok(%rdsck,1,32) == 230) { ftp.list }
  if ($gettok(%rdsck,1,32) == 227) { 
    set %ftp.port $calc($gettok(%rdsck,5,44) * 256 + $remove($gettok(%rdsck,6,44),$chr(41),.))
    sockopen ftp.data %address %ftp.port
  }
  if (CWD command successful. isin %rdsck) ftp.list
}
on *:sockread:ftp.data:{
  if (%intention == list) {
    sockread %rdsck
    echo -at $iif($left(%rdsck,1) == d,9D,4F) 9- $gettok(%rdsck,9-,32) --4 $bytes($gettok(%rdsck,5,32)).suf -- $gettok(%rdsck,6,32) $gettok(%rdsck,7,32) $gettok(%rdsck,8,32) 
  }
  if (%intention == download) { 
    sockread &RDSCK
    bwrite %ftp.file -1 -1 &rdsck
  }
}
on *:sockclose:ftp.data:{
  echo -at  $+ $bytes($sock(ftp.data).rcvd).suf received succesfully in $calc(($ticks - %ticks) / 1000) seconds ( $+ $round($calc(($sock(ftp.data).rcvd / 1000) / $calc(($ticks - %ticks) / 1000)),2) KB/s $+ )
}
on *:SOCKWRITE:ftp.data:{
  inc %å
  if ($sock(ftp.data).sq == 0) {
    bread %ftp.file $calc(%å * %ftp.packetsize) %ftp.packetsize &ftp.data
    echo -at $calc(%å * 925)
    if ($bvar(&ftp.data,0) == 0) sockclose ftp.data
    if ($bvar(&ftp.data,0) != 0) sockwrite ftp.data $bvar(&ftp.data,1,$bvar(&ftp.data,0)).text
  }
}
alias ftp {
  sockwrite -n ftp $1-
  echo -at 4 -- $remove($1-,%pass,(Hidden))
}
alias f8 { sockclose ftp.data }
alias ftp.list {
  set %intention list
  FTP PASV
  FTP LIST
  set %ticks $ticks
}
alias ftp.download {
  set %ftp.file $1- 
  set %intention download
  .remove %ftp.file
  FTP PASV
  FTP RETR %ftp.file
  set %ticks $ticks
}
alias ftp.upload { 
  set %ftp.packetsize 925
  unset %ftp.size
  set %å 0
  set %ftp.file $1- 
  set %intention upload
  FTP PASV
  FTP STOR %ftp.file
}
alias FTP.start {
  set %address $1
  set %port $2
  set %user $3
  set %pass $4
  sockopen ftp %address %port
}
  


am a big noob
#53711 11/10/03 05:31 PM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Quote:
sockwrite ftp.data $bvar(&ftp.data,1,$bvar(&ftp.data,0)).text

$bvar is probably why some data was not sent correctly.

mIRC allows us to specify the name of a binvar as the first parameter
of /sockwrite, and it will then access the var and send the exact
data through the socket.

Try: /sockwrite ftp.data &ftp.data

(This also means you can now forget about the line length limit issues
and /bread even 8192 bytes each time.)

And btw, if you happen to use $bvar(), note you can use N-[N] to
reference to a range of values, eg. $bvar(&var,1-).text returns the
whole content of a binvar.

If you were only looking for an easy way to upload files, this tutorial
would interest you.

#53712 11/10/03 07:04 PM
Joined: Dec 2002
Posts: 32
J
Jaakko Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Dec 2002
Posts: 32
Thank you so much !! smile


am a big noob

Link Copied to Clipboard