FTP utilities #87
Aliases: FTP utilities
16 verbs · 7 properties · 0 children
Verbs
| Verb | Spec | Flags | Definer | Lines |
|---|---|---|---|---|
open | this none this | rxd | #87 | 15 |
close | this none this | rxd | #87 | 12 |
do_command | this none this | rxd | #87 | 6 |
wait_for_response | this none this | rxd | #87 | 23 |
controls | this none this | rxd | #87 | 1 |
get_messages | this none this | rxd | #87 | 10 |
open_data | this none this | rxd | #87 | 24 |
get_data | this none this | rxd | #87 | 9 |
put_data | this none this | rxd | #87 | 16 |
trusted | this none this | rxd | #87 | 1 |
listen | this none this | rxd | #87 | 14 |
close_data | this none this | rxd | #87 | 12 |
get | this none this | rxd | #87 | 11 |
init_for_core | this none this | rxd | #87 | 5 |
put | this none this | rxd | #87 | 11 |
data_connection | this none this | rxd | #87 | 4 |
Properties
| Property | Definer | Flags | Owner | Value |
|---|---|---|---|---|
trusted | #87 | rc | #2 | 1 |
port | #87 | rc | #2 | 21 |
connections | #87 | | #2 | {} |
key | #1 | c | #2 | 0 |
aliases | #1 | rc | #2 | {"FTP utilities"} |
description | #1 | rc | #2 | <clear> |
object_size | #1 | r | #36 | {9061, 1539462952} |
Ancestry
Ancestors (nearest first): #1 Root Class
Children: none
Call graph
Source
open
Referenced by
Source
1if (!this:trusted(caller_perms())) 2return E_PERM; 3endif 4{host, ?user = "", ?pass = ""} = args; 5if (typeof(conn = $network:open(host, this.port)) == ERR) 6return {"Unable to connect to host."}; 7endif 8this.connections = {@this.connections, {conn, caller_perms(), {}, 0, {}}}; 9if (((!this:wait_for_response(conn)) || (user && (!this:do_command(conn, "USER " + user)))) || (pass && (!this:do_command(conn, "PASS " + pass)))) 10messages = this:get_messages(conn); 11this.connections = listdelete(this.connections, $list_utils:iassoc(conn, this.connections)); 12$network:close(conn); 13return messages; 14endif 15return conn;
close
Referenced by
Source
1conn = args[1]; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5this:do_command(conn, "QUIT"); 6info = $list_utils:assoc(conn, this.connections); 7this.connections = setremove(this.connections, info); 8$network:close(conn); 9if ($network:is_open(info[4])) 10$network:close(info[4]); 11endif 12return info[3];
do_command
Referenced by
- #87:open line 9:
this:do_command - #87:open line 9:
this:do_command - #87:close line 5:
this:do_command - #87:open_data line 7:
this:do_command - #87:get line 8:
this:do_command - #87:put line 8:
this:do_command
Source
1{conn, cmd, ?nowait = 0} = args; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5$network:notify(conn, cmd); 6return nowait ? 1 | this:wait_for_response(conn);
wait_for_response
Referenced by
- #87:open line 9:
this:wait_for_response - #87:do_command line 6:
this:wait_for_response
Source
1{conn, ?first_only = 0} = args; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5matchstr = first_only ? "^[1-9][0-9][0-9] " | "^[2-9][0-9][0-9] "; 6messages = {}; 7result = ""; 8while ((typeof(result) == STR) && (!match(result, matchstr))) 9result = $network:read(conn); 10messages = {@messages, result}; 11endwhile 12i = $list_utils:iassoc(conn, this.connections); 13this.connections[i][3] = {@this.connections[i][3], @messages}; 14if (typeof(result) == STR) 15if (result[1] in {"4", "5"}) 16player:tell(result); 17return E_NONE; 18else 19return 1; 20endif 21else 22return result; 23endif
controls
Referenced by
- #87:close line 2:
this:controls - #87:do_command line 2:
this:controls - #87:wait_for_response line 2:
this:controls - #87:get_messages line 2:
this:controls - #87:open_data line 2:
this:controls - #87:get_data line 2:
this:controls - #87:put_data line 2:
this:controls - #87:close_data line 2:
this:controls
Source
1return args[1].wizard || ({@$list_utils:assoc(args[2], this.connections), 0, 0}[2] == args[1]);
get_messages
Referenced by
- #87:open line 10:
this:get_messages - #87:open_data line 8:
this:get_messages
Source
1{conn, ?keep = 0} = args; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5i = $list_utils:iassoc(conn, this.connections); 6messages = this.connections[i][3]; 7if (!keep) 8this.connections[i][3] = {}; 9endif 10return messages;
open_data
Referenced by
Source
1conn = args[1]; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5i = $list_utils:iassoc(conn, this.connections); 6if (!$network:is_open(this.connections[i][4])) 7this:do_command(conn, "PASV"); 8msg = (msg = this:get_messages(conn, 1))[$]; 9if (msg[1..3] != "227") 10return E_TYPE; 11elseif (!(match = match(msg, "(%([0-9]+%),%([0-9]+%),%([0-9]+%),%([0-9]+%),%([0-9]+%),%([0-9]+%))"))) 12return E_TYPE; 13elseif (typeof(dconn = $network:open(substitute("%1.%2.%3.%4", match), (toint(substitute("%5", match)) * 256) + toint(substitute("%6", match)))) == ERR) 14return dconn; 15else 16this.connections[i][4] = dconn; 17endif 18this.connections[i][5] = E_INVARG; 19set_task_perms(caller_perms()); 20fork (0) 21this:listen(conn, dconn); 22endfork 23endif 24return 1;
get_data
Referenced by
- #87:get line 8:
this:get_data
Source
1{conn, ?nowait = 0} = args; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5i = $list_utils:iassoc(conn, this.connections); 6while ((!nowait) && (this.connections[i][5] == E_INVARG)) 7suspend(0); 8endwhile 9return this.connections[i][5];
put_data
Referenced by
- #87:put line 8:
this:put_data
Source
1{conn, data} = args; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5i = $list_utils:iassoc(conn, this.connections); 6dconn = this.connections[i][4]; 7if (!$network:is_open(dconn)) 8return E_INVARG; 9else 10for line in (data) 11notify(dconn, line); 12$command_utils:suspend_if_needed(0); 13endfor 14this:close_data(conn); 15this.connections[i][4] = 0; 16endif
trusted
Referenced by
Source
1return args[1].wizard || ((typeof(this.trusted) == LIST) ? args[1] in this.trusted | this.trusted);
listen
Referenced by
- #87:open_data line 21:
this:listen
Source
1if (caller != this) 2return E_PERM; 3endif 4{conn, dconn} = args; 5data = {}; 6line = `read(dconn) ! ANY'; 7while (typeof(line) == STR) 8data = {@data, line}; 9line = read(dconn); 10(ticks_left() < 4000) && suspend(0); 11endwhile 12if (i = $list_utils:iassoc(conn, this.connections)) 13this.connections[i][5] = data; 14endif
close_data
Referenced by
- #87:put_data line 14:
this:close_data
Source
1conn = args[1]; 2if (!this:controls(caller_perms(), conn)) 3return E_PERM; 4endif 5if (!$network:is_open(dconn = $list_utils:assoc(conn, this.connections)[4])) 6return E_INVARG; 7else 8$network:close(dconn); 9"...let the reading task come to terms with its abrupt superfluousness..."; 10suspend(0); 11return 1; 12endif
get
Referenced by
none
Source
1":get(host, username, password, filename)"; 2if (!this:trusted(caller_perms())) 3return E_PERM; 4endif 5if (typeof(conn = this:open(@args[1..3])) != OBJ) 6return E_NACC; 7else 8result = (this:open_data(conn) && this:do_command(conn, "RETR " + args[4])) && this:get_data(conn); 9this:close(conn); 10return result; 11endif
init_for_core
Referenced by
none
Source
1if (caller_perms().wizard) 2this.connections = {}; 3this.trusted = 1; 4pass(@args); 5endif
put
Referenced by
none
Source
1":put(host, username, password, filename, data)"; 2if (!this:trusted(caller_perms())) 3return E_PERM; 4endif 5if (typeof(conn = this:open(@args[1..3])) != OBJ) 6return E_NACC; 7else 8result = (this:open_data(conn) && this:do_command(conn, "STOR " + args[4], 1)) && this:put_data(conn, args[5]); 9this:close(conn); 10return result; 11endif
data_connection
Referenced by
none
Source
1"return the data connection associated with the control connection args[1]"; 2conn = args[1]; 3i = $list_utils:iassoc(conn, this.connections); 4return this.connections[i][4];