mIRC Home    About    Download    Register    News    Help

Print Thread
#12623 23/02/03 10:10 AM
Joined: Feb 2003
Posts: 23
M
Mog Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 23
Is there a way to have mIRC open a port to accept incoming files? Like from an FTP or something.

#12624 23/02/03 10:39 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
/help /socklisten


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12625 23/02/03 10:49 AM
Joined: Feb 2003
Posts: 23
M
Mog Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 23
I know about socklisten, but how do I use socklisten to recieve a file?

#12626 23/02/03 03:50 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
For the FTP protocol data connection, I don't listen for a connection; I use the PASV command and connect to the IP port the server gives me. I assume (though I might very well be wrong) that if you don't use the PASV command, you still connect to port 20 on the server's IP. (Perhaps I'll have to try that sometime -- or maybe reread the FTP protocol RFC.)


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12627 24/02/03 07:39 AM
Joined: Feb 2003
Posts: 23
M
Mog Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 23
How does that help me using an FTP to connect to an open socks port on MIRC to recieve a file? I can get an ftp to connect to an open socks port, that's fine ... I can't get a socks port to recieve a file ...

#12628 24/02/03 03:10 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
There are two FTP commands you can use to set up a socket to transfer data: PORT and PASV. In both cases, the IP and port are comma-delimited in decimal, with the IP forming the first four values. The port can be calculated by multiplying the fifth value by 256 and adding the sixth value. Assume for these examples that the FTP server's IP is 87.65.43.21 and your address is 12.34.56.78. The data port you will use is port 3956 (randomly chosen by me).

PASV
The PASV command tells the server to enter Passive mode and give you its IP and Data port it will be listening on for the next data transaction. It takes no parameters. The server responds with its comma-delimited IP and the two decimal values to create the port number.

Example
PASV
227 Entering Passive Mode (87,65,43,21,193,154)
connecting to 87.65.43.21:49562
- -
connecting to 87.65.43.21:49562
Connected to 87.65.43.21 port 49562

Script sample
Code:
  
  sockread %text
  if $gettok(%text,1,32) == 227 {
    var %last = $left($gettok(%text, 2, 40), -1)
    var %IP = $replace($gettok(%last, 1-4, 44), $chr(44), $chr(46)
    var %Port = $calc($gettok(%last, 5, 44) * 256 + $gettok(%last, 6, 44))
    sockopen FTP.Data %IP %Port
  }


PORT <i1,i2,i3,i4,p1,p2>
The PORT command tells the server that you will be listening on your IP and the port it can connect to on that IP. It takes 6 comma-delimited parameters, the first four being the comma-delimited IP and the last two being the two decimal values calculated from the port number. i1.i2.i3.i4 on port (p1*256+p2).

Example
PORT 12,34,56,78,15,124
200 PORT command successful.

Script sample
Code:
 
  var %port = 3956
  socklisten -d $ip FTP.Data.Connection %port
  var %connect.string = $replace($ip, $chr(46), $chr(44)) $+ , $+ $int($calc(%port / 256)) $+ , $+ $calc(%port % 256)
  sockwrite -n $sockname PORT %connect.string
 
on *:SOCKLISTEN:FTP.Data.Connection: sockaccept FTP.Data

In both cases, you will need to read in the data using an on *:SOCKREAD:FTP.Data: event.
Code:
 
on *:SOCKREAD:FTP.Data:{
  ;  Script to read in the data, such as into a file, goes here
}

As I'm sure you can foresee, there is a bit more scripting to do if you use the PORT command and might have multiple FTP Data connections open simultaneously. Also, due to some attacks using a basic "flaw" in the FTP protocol concerning third-party PORT commands, some FTP server administrators have disallowed the use of the PORT command entirely (which is why I use the PASV command).

This post shows how you can download the file you want to download using the HTTP protocol. It would be even simpler for FTP since you don't have to skip any headers and can read in from the socket in binary and write it out in binary very quickly. All your status information will still show up on the control socket.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12629 24/02/03 11:50 PM
Joined: Feb 2003
Posts: 23
M
Mog Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 23
Okay, here is what I was doing ... your thing helped me, but not too much. Instead of using socks to transfer the file, what I was doing was having the script find the port and switch the dcc server port. When you gave me the info, I tried to use the ($5 * 256) + $6 based off the comma ip,port thing but that didn't do when I would upload a file, the port was switched to one that FlashFXP was sending on, but nothing came in over the dcc server. So I changed it to pasv mode and replied with the $replace(ip,46,44) $+ , $+ $5 * 256 + $6 $+ , $+ $6 thing .. and I go the file to transfer over the dccserver, but ... no window showed up, and the file would max out at 52k. Got any ideas?

#12630 25/02/03 08:22 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
I am surprised you got all the way to 52K. The PASV command (again) does not take any parameters, but the PORT command does. The primary problem, though, is that you are trying to use the DCC protocol when you're actually supposed to be using the FTP protocol. They are not the same.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#12631 25/02/03 09:45 PM
Joined: Feb 2003
Posts: 23
M
Mog Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 23
hehe, yeah =( but it would be nice.

#12632 25/02/03 09:53 PM
Joined: Feb 2003
Posts: 23
M
Mog Offline OP
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Feb 2003
Posts: 23
This might be a little harder to answer ... I dunno if its even possible. But is there a way to make mIRC know if a file is complete? Like is there a way to calculate how big the file is supposed to be? Then base it off how big the file is?


Link Copied to Clipboard