mIRC Home    About    Download    Register    News    Help

Print Thread
#38138 24/07/03 10:00 AM
Joined: Dec 2002
Posts: 94
K
krunch Offline OP
Babel fish
OP Offline
Babel fish
K
Joined: Dec 2002
Posts: 94
im trying to build a socket ftp
how do I get it to send the file?

any information on this will be great


Lets get dirty
#38139 24/07/03 10:20 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Before you get into scripting an ftp client merely for uploading a file, try this handy tutorial.

#38140 24/07/03 10:57 AM
Joined: Jul 2003
Posts: 2
S
Bowl of petunias
Offline
Bowl of petunias
S
Joined: Jul 2003
Posts: 2
ftp://ftp.rfc-editor.org/in-notes/rfc959.txt

It explains the file transfer protocol in details. It helped me making a ftp client using mirc scripting.

when you have sent USER and PASS commands, you
can send PASV. Then the server will give you an address/port to connect to (as explained in the url above).

When you have connected to that address, try something like this:
on 1:sockopen:data*:{ /if ($sockerr) { /halt }
/echo -s $chr(3) $+ 2*** Sending file.....
/sockwrite -n $sockname STOR thefiletomake.xxx
}

Wait for reply code 150, then write your file to the data connection.


#38141 24/07/03 12:27 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
FTP file transfers require two different sockets. The control socket is the socket on which you receive status information (in numerics) and send commands. The data socket(s) is(are) where you send or receive data (such as the results of a LIST command or sending/receiving a file). Using the PASV (Passive) command requests a different port for each such transaction, as shown below, for you to open a new socket to; some FTP servers require PASV, others don't and you can just keep reopening a socket to port 20.

Here is a sample FTP session that connects to an FTP server, logs in as Hammer, switches to the www directory, uploads a file and then exits. This log was generated using WS_FTP Lite Edition and then cleaned up to exclude non-essentials (like multiple LISTs), sanitized, colorized and notes added to show what happens and where/when..
  • Grey text is what your script will /echo out of its own accord: Version info, socket info, etc.[color:#840017]
  • Maroon text is sent to you from the server. Numerics and changeable data are in bold. All of these lines are read in the on SOCKREAD event.
  • Green text is send by you to the server. Command names are in bold; parameters are not.
WINSOCK.DLL: WinSock 2.0
WS_FTP LE 5.08 2000.01.13, Copyright © 1992-2000 Ipswitch, Inc.
--> local chdir to C:\FTP
--> connecting to 12.34.56.78:21 [sockopen FTP 12.34.56.78 21]
--> Connected to 12.34.56.78 port 21 [on *:SOCKOPEN:FTP:]
220 ftp.account.net FTP server (Version 6.00) ready. [on *:SOCKREAD:FTP:]
USER Hammer [sockwrite -n FTP USER username]
331 Password required for Hammer.
PASS dIdYoUrEaLlYtHiNkIdTeLlYoUmYpAsSwOrD [sockwrite -n FTP PASS password]
230 User Hammer logged in.
CWD /home/Hammer/www/ [sockwrite -n FTP CWD /home/username/www/]
250 CWD command successful.
--> sending regex.html as regex.html (1 of 1)
TYPE I [sockwrite -n FTP TYPE I]
200 Type set to I.
PASV [sockwrite -n FTP PASV]
227 Entering Passive Mode (12,34,56,78,192,6)
***; [192 * 256 + 6 = 49158] so /sockopen FTPData 12.34.56.78 49158
--> connecting to 12.34.56.78:49158
--> Connected to 12.34.56.78 port 49158 [on *:SOCKOPEN:FTPData:]
STOR regex.html [sockwrite -n FTP STOR filename.txt]
150[/b] Opening BINARY mode data connection for 'regex.html'.
*** ; Use 8192-byte, 4096-byte, 2048-byte or 1024-byte chunks to fill up the send queue.
*** ; BRead C:\mIRC\FTP\filename.txt into a &binvar
*** ; SockWrite FTPdata &binvar
*** ; Check to see if the buffer is full or if there's room for more ($sock(FTP).sq tells you if you have more room)
*** ; Continue till buffer is full
*** ; Use on *:SOCKWRITE:FTPData: to retrigger the BRead/SockWrite process (if necessary)
*** ; Repeat until file is sent and $sock(FTPData).sq is 0.
*** ; Then /sockclose FTPData
--> Transmitted 10060 bytes in 0.1 secs, (98.24 KBps), transfer succeeded
226 Transfer complete.
QUIT [sockwrite -n FTP QUIT]
221 Goodbye.[/b]
*** ; on *:SOCKCLOSE:FTP: happens when the server closes the socket.[/color]

For more information, please see RFC 959 - File Transfer Protocol (FTP).


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C

Link Copied to Clipboard