IRC DCC Receive files

2019-09-10 05:36发布

I premise that I have already read the IRC RFC. The only thing that I know: when a user sends me a File i receive a CTCP like this: DCC SEND < filename > < ipaddress > < port > < filesize > Where IPAddress must be converted from long to standard IP format.

After conversion how can I start receiving file? I stopped here:

Dim sendMatch As Match = Regex.Match(b_data, "DCC SEND (.*?) (\d+) (\d+) (\d+?).?$")
   If (sendMatch.Captures.Count > 0) Then
       Dim send_filename As String = sendMatch.Groups.Item(1).Value
       Dim send_fromip As String = IPConvert(sendMatch.Groups.Item(2).Value)
       Dim send_fromport As String = sendMatch.Groups.Item(3).Value
       Dim send_filesize As String = sendMatch.Groups.Item(4).Value
       ...

Sorry for my bad english, and thanks in advance!

标签: vb.net irc
1条回答
ら.Afraid
2楼-- · 2019-09-10 06:40

The parameters given to the CTCP DCC command include a suggested filename, IP address (this is ipv4 ONLY, encoded as a 32 bit integer in ASCII format, e.g. 2130706433 meaning 127.0.0.1. The next field contains the port number and the final field contains the file size.

Simply connect to the given IP on the given port via a TCP connection, and continually receive in 4k blocks. After each block received send a 4 byte count of how many bytes total you've received so far in network byte order. Continue this until the connection closes and/or you've received as many bytes as given for the file size. You must usually send the count of bytes for the final block before the connection closes.

Generally, the sending client MAY close the connection on completion of the send, but don't rely on them to do this.

Also, never EVER just take the given filename at face value, give the user the ability to select their own and to sanitise it, filtering out malicious file types, otherwise you could be on the receiving end of a DCC SEND for a file for example with the name "..\..\..\..\..\windows\notepad.exe" or such which if taken directly will overwrite a system file if the user has the correct permissions.

You can find more information here.

Hope this helps!

查看更多
登录 后发表回答