April 23-27, 2002 - Version 1 - Draft 2
hypothetic.org

MSN Instant Messenger Protocol

Overview Basics Connecting Session Messaging File Transfer Other FAQ Research

Sending a File

Sending the Invitation

Before sending the file, you need to send an invitation message for file transfer over a switchboard session. The body of this message ends with two newlines. Below is an example.

MSG 4 N 277
MIME-Version: 1.0
Content-Type: text/x-msmsgsinvite; charset=UTF-8

Application-Name: File Transfer
Application-GUID: {5D3E02AB-6190-11d3-BBBB-00C04F795683}
Invitation-Command: INVITE
Invitation-Cookie: 33267
Application-File: readme.txt
Application-FileSize: 60904

The Invitation-Cookie is a random number, with the same domain as a transaction ID (a number between 0 and 4294967295 (2^32 - 1)). The cookie identifies every followup invitation as being associated with this one, so you will need to remember it. Replace the Application-File with the filename of the file you are sending, and replace the Application-FileSize with the size of the file in bytes.

After receiving this invitation, the recipient should reply with another invitation with the Invitation-Command of either ACCEPT or CANCEL. Below is an example of what you might receive if they accept the file.

MSG example@passport.com Tim 179
MIME-Version: 1.0
Content-Type: text/x-msmsgsinvite; charset=UTF-8

Invitation-Command: ACCEPT
Invitation-Cookie: 33267
Launch-Application: FALSE
Request-Data: IP-Address:

Or if they refuse the file . . .

MSG example@passport.com Tim 146
MIME-Version: 1.0
Content-Type: text/x-msmsgsinvite; charset=UTF-8

Invitation-Command: CANCEL
Invitation-Cookie: 33267
Cancel-Code: REJECT

If they accept your invitation, you will need to send them another invitation, once again, ending with two newlines. Below is an example.

MSG 4 N 238
MIME-Version: 1.0
Content-Type: text/x-msmsgsinvite; charset=UTF-8

Invitation-Command: ACCEPT
Invitation-Cookie: 33267
IP-Address: 10.44.102.65
Port: 6891
AuthCookie: 93301
Launch-Application: FALSE
Request-Data: IP-Address:

The IP-Address is your IP address that they will be connecting to. The Port is the port number you will be listening on. The port is usually 6891, but if that port isn't available, you will need to send anoter. The Auth-Cookie is another random number of the same size, and it will be used to verify the correct recipient.

Authorizing Login

As soon as the recipient receives your last invitation message, they will connect to your IP address at the specified port. As soon as they have successfully connected, they will send VER MSNFTP followed by a newline. Notice that there are no transaction IDs exchanged during a file transfer session. Reply to their message with VER MSNFTP again. They will then send USR with their Passport as the first parameter and the Auth-Cookie as the second. If these are valid, send FIL with the number of bytes in the file as the only parameter. They will reply to this with TFR with no parameter, and that is your cue to begin sending the file. Below is an example of the whole conversation.

<o> Incoming Connection on Port: 6891

<<< VER MSNFTP

>>> VER MSNFTP

<<< USR myname@msn.com 93301

>>> FIL 60904

<<< TFR

<o> Being Sending File . . .

Sending File

Every packet you send will begin with a three byte header. The first byte will always have an ASCII value of 0. The second and third bytes make up the size of the packet being sent. It has something to do with high and low order stuff, but I don't know the terminology. The value of the second byte plus 256 times the value of the third byte will be the size of the packet. To find these numbers, you can do integer division and modulus with the packet size and 256. Every packet should be 2045 bytes long, except for the last one, which will have the remaining number of bytes.

After sending the three byte header, you will need to send a packet of binary data from the file that corresponds with the three byte header. Keep sending headers and packets until the file is completely transferred.

Ending Transfer

When the file has been completely transferred, the recipient will know since it knows how many bytes are in the file. The recipient will send BYE 16777989 ending with a newline, and as the sender, you are expected to close the connection. If the receiver doesn't send BYE quickly enough for you (about 1 minute in the official client), send an invitation command in the switchboard session with "Invitation-Command: CANCEL" and "Cancel-Code: FTTIMEOUT".

If you want to cancel the transfer in the middle, send a header with the first byte value of 1 and the second and third both as 0. I think the other side will close the connection.

If the other side chooses to cancel the transfer in the middle, they will send CCL followed by a newline. I think the sender is supposed to close the socket.

Receiving a File

Receiving a File

Receiving a file works the same way as sending a file, except reversed. I would rather not explain it again!

Copyright ©2002-2003 to Mike Mintz.