• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/tcl-105/tcl_ext/tcllib/tcllib/modules/ftpd/

Lines Matching +refs:ftpd +refs:command +refs:ABOR

0 # ftpd.tcl --
12 # RCS: @(#) $Id: ftpd.tcl,v 1.30 2010/01/20 18:22:42 andreas_kupries Exp $
15 # Define the ftpd package version 1.2.5
18 namespace eval ::ftpd {
47 authUsrCmd {::ftpd::anonAuth} \
48 authFileCmd {::ftpd::fileAuth} \
49 logCmd {::ftpd::logStderr} \
50 fsCmd {::ftpd::fsFile::fs} \
57 ABOR {ABOR (abort operation)} \
84 REST {(restart command); unimplemented.} \
114 # ::ftpd::config --
124 # login. Defaults to ::ftpd::anonAuth
128 # ::ftpd::userAuth
131 # ::ftpd::logStderr
134 # Default is ::ftpd::fsFile::fs
142 proc ::ftpd::config {args} {
151 # command multiple times without resetting already set values
166 # ::ftpd::hasCallback --
181 proc ::ftpd::hasCallback {callbackType} {
189 # ::ftpd::logStderr --
205 proc ::ftpd::logStderr {severity text} {
215 # ::ftpd::Log --
217 # Used for all ftpd logging.
228 # The ftpd logCmd callback is called with the specified severity and
231 proc ::ftpd::Log {severity text} {
247 # ::ftpd::fileAuth --
254 # connect to the ftpd.
265 proc ::ftpd::fileAuth {user path operation} {
286 # ::ftpd::anonAuth --
289 # attempted login. This is the default ftpd authUsrCmd callback. By
296 # connect to the ftpd.
298 # connect to the ftpd.
306 proc ::ftpd::anonAuth {user pass} {
330 # ::ftpd::unixAuth --
333 # attempted login. This is an alternative to the default ftpd
340 # connect to the ftpd.
342 # connect to the ftpd.
350 proc ::ftpd::unixAuth {user pass} {
381 ::ftpd::Log debug $passwords
410 # ::ftpd::server --
418 # attempting to connect to the ftpd.
425 # ::ftpd::accept when it is connected to.
427 proc ::ftpd::server {{myaddr {}}} {
430 set f [socket -server ::ftpd::accept -myaddr $myaddr $port]
432 set f [socket -server ::ftpd::accept $port]
438 # ::ftpd::accept --
442 # printed out, and a ftpd::Read filevent is placed on the socket.
445 # sock - The channel for this connection to the ftpd.
453 # Sets up a ftpd::Read fileevent to trigger whenever the channel is
457 proc ::ftpd::accept {sock ipaddr client_port} {
458 upvar #0 ::ftpd::$sock data
500 state command \
508 fileevent $sock readable [list ::ftpd::Read $sock]
515 # ::ftpd::Read --
517 # Checks the state of a channel and then reads a command from the
518 # channel if it is not at end of file yet. If there is a command named
519 # ftpd::command::* where '*' is the all upper case name of the command,
520 # then that proc is called to handle the command with the remaining parts
521 # of the command that was read from the channel as arguments.
524 # sock - The channel for this connection to the ftpd.
530 # Runs the appropriate command depending on the state in the state
531 # machine, and the command that is specified.
533 proc ::ftpd::Read {sock} {
534 upvar #0 ::ftpd::$sock data
543 command {
544 gets $sock command
546 if {![regexp {^([^ ]+) (.*)$} $command -> cmd argument]} {
547 if {![regexp {^([^ ]+)$} $command -> cmd]} {
548 # Very bad command syntax.
554 auto_load ::ftpd::command::$cmd
566 } elseif {[info command ::ftpd::command::$cmd] != ""} {
567 Log debug $command
568 ::ftpd::command::$cmd $sock $argument
571 Log error "Unknown command: $cmd"
572 puts $sock "500 Unknown command $cmd"
582 # ::ftpd::Finish --
584 # Closes the socket connection between the ftpd and client.
587 # sock - The channel for this connection to the ftpd.
595 proc ::ftpd::Finish {sock} {
596 upvar #0 ::ftpd::$sock data
601 ## User specified a close command so invoke it
612 # ::ftpd::FinishData --
615 # command is recieved.
618 # sock - The channel for this connection to the ftpd.
626 proc ::ftpd::FinishData {sock} {
627 upvar #0 ::ftpd::$sock data
633 # ::ftpd::Fs --
635 # The general filesystem command. Used as an intermediary for filesystem
637 # ::ftpd::Fs command will call out to the fsCmd callback with the
656 # command - The filesystem command (one of dlist, retr, or
681 # callback configured for the ftpd.
683 proc ::ftpd::Fs {command path args} {
690 return [eval [list $cfg(fsCmd) $command $path] $args]
693 # Create a namespace to hold one proc for each ftp command (in upper case
699 namespace eval ::ftpd::command {
703 # ::ftpd::command::ABOR --
705 # Handle the ABOR ftp command. Closes the data socket if it
709 # sock - The channel for this connection to the ftpd.
710 # list - The arguments to the APPE command.
719 proc ::ftpd::command::ABOR {sock list} {
721 ::ftpd::FinishData $sock
722 puts $sock "225 ABOR command successful."
727 # ::ftpd::command::APPE --
729 # Handle the APPE ftp command. Gets a writable channel for the file
730 # specified from ::ftpd::Fs and copies the data from data(sock2) to
735 # sock - The channel for this connection to the ftpd.
736 # list - The arguments to the APPE command.
745 proc ::ftpd::command::APPE {sock filename} {
746 upvar #0 ::ftpd::$sock data
749 if {[::ftpd::hasCallback authFileCmd]} {
750 set cmd $::ftpd::cfg(authFileCmd)
761 if {![catch {::ftpd::Fs append $path $data(mode)} f]} {
763 fcopy $data(sock2) $f -command [list ::ftpd::GetDone $sock $data(sock2) $f ""]
766 ::ftpd::FinishData $sock
771 # ::ftpd::command::CDUP --
773 # Handle the CDUP ftp command. Change the current working directory to
777 # sock - The channel for this connection to the ftpd.
778 # list - The arguments to the CDUP command.
786 proc ::ftpd::command::CDUP {sock list} {
787 upvar #0 ::ftpd::$sock data
790 puts $sock "200 CDUP command successful."
794 # ::ftpd::command::CWD --
796 # Handle the CWD ftp command. Change the current working directory.
799 # sock - The channel for this connection to the ftpd.
800 # list - The arguments to the CWD command.
808 proc ::ftpd::command::CWD {sock relativepath} {
809 upvar #0 ::ftpd::$sock data
812 puts $sock "250 CWD command successful."
818 puts $sock "250 CWD command successful."
823 puts $sock "250 CWD command successful."
827 # ::ftpd::command::DELE --
829 # Handle the DELE ftp command. Delete the specified file.
832 # sock - The channel for this connection to the ftpd.
833 # list - The arguments to the DELE command.
841 proc ::ftpd::command::DELE {sock filename} {
842 upvar #0 ::ftpd::$sock data
845 if {[::ftpd::hasCallback authFileCmd]} {
846 set cmd $::ftpd::cfg(authFileCmd)
854 if {[catch {::ftpd::Fs delete $path $sock} msg]} {
860 # ::ftpd::command::HELP --
862 # Handle the HELP ftp command. Display a list of commands
866 # sock - The channel for this connection to the ftpd.
867 # list - The arguments to the HELP command.
875 proc ::ftpd::command::HELP {sock command} {
876 upvar #0 ::ftpd::$sock data
878 if {$command != ""} {
879 set command [string toupper $command]
880 if {![info exists ::ftpd::commands($command)]} {
881 puts $sock "502 Unknown command '$command'."
882 } elseif {[info commands ::ftpd::command::$command] == ""} {
883 puts $sock "214 $command\t$::ftpd::commands($command)"
885 puts $sock "214 Syntax: $::ftpd::commands($command)"
888 set commandList [lsort [array names ::ftpd::commands]]
892 if {[info commands ::ftpd::command::$commandName] == ""} {
906 puts $sock "214 Direct comments to $::ftpd::contact."
912 # ::ftpd::command::LIST --
914 # Handle the LIST ftp command. Lists the names of the files in the
918 # sock - The channel for this connection to the ftpd.
919 # list - The arguments to the LIST command.
927 proc ::ftpd::command::LIST {sock filename} {
928 ::ftpd::List $sock $filename list
932 # ::ftpd::command::MDTM --
934 # Handle the MDTM ftp command. Prints the modification time of the
938 # sock - The channel for this connection to the ftpd.
939 # list - The arguments to the MDTM command.
947 proc ::ftpd::command::MDTM {sock filename} {
948 upvar #0 ::ftpd::$sock data
951 if {[catch {::ftpd::Fs mtime $path $sock} msg]} {
953 ::ftpd::FinishData $sock
958 # ::ftpd::command::MKD --
960 # Handle the MKD ftp command. Create the specified directory.
963 # sock - The channel for this connection to the ftpd.
964 # list - The arguments to the MKD command.
972 proc ::ftpd::command::MKD {sock filename} {
973 upvar #0 ::ftpd::$sock data
977 if {[::ftpd::hasCallback authFileCmd]} {
978 set cmd $::ftpd::cfg(authFileCmd)
986 if {[catch {::ftpd::Fs mkdir $path $sock} f]} {
992 # ::ftpd::command::NOOP --
994 # Handle the NOOP ftp command. Do nothing.
997 # sock - The channel for this connection to the ftpd.
998 # list - The arguments to the NOOP command.
1006 proc ::ftpd::command::NOOP {sock list} {
1008 puts $sock "200 NOOP command successful."
1012 # ::ftpd::command::NLST --
1014 # Handle the NLST ftp command. Lists the full file stat of all of the
1018 # sock - The channel for this connection to the ftpd.
1019 # list - The arguments to the NLST command.
1027 proc ::ftpd::command::NLST {sock filename} {
1028 ::ftpd::List $sock $filename nlst
1032 # ::ftpd::command::PASS --
1034 # Handle the PASS ftp command. Check whether the specified user
1037 # not ::ftpd::Log is used to log and error, and an "Access Denied"
1041 # sock - The channel for this connection to the ftpd.
1042 # list - The arguments to the PASS command.
1051 proc ::ftpd::command::PASS {sock password} {
1052 upvar #0 ::ftpd::$sock data
1060 ::ftpd::Log debug "pass <$data(pass)>"
1062 if {![::ftpd::hasCallback authUsrCmd]} {
1070 set cmd $::ftpd::cfg(authUsrCmd)
1076 ::ftpd::Log error "AuthUsr error: $res"
1079 ::ftpd::Log note "AuthUsr: Access denied to <$data(user)> <$data(pass)>."
1090 # ::ftpd::command::PORT --
1092 # Handle the PORT ftp command. Create a new socket with the specified
1096 # sock - The channel for this connection to the ftpd.
1097 # list - The arguments to the PORT command.
1105 proc ::ftpd::command::PORT {sock numbers} {
1106 upvar #0 ::ftpd::$sock data
1109 ::ftpd::FinishData $sock
1118 # ::ftpd::command::PWD --
1120 # Handle the PWD ftp command. Prints the current working directory to
1124 # sock - The channel for this connection to the ftpd.
1125 # list - The arguments to the PWD command.
1133 proc ::ftpd::command::PWD {sock list} {
1134 upvar #0 ::ftpd::$sock data
1135 ::ftpd::Log debug $data(cwd)
1140 # ::ftpd::command::QUIT --
1142 # Handle the QUIT ftp command. Closes the socket.
1145 # sock - The channel for this connection to the ftpd.
1146 # list - The arguments to the PWD command.
1154 proc ::ftpd::command::QUIT {sock list} {
1155 ::ftpd::Log note "Closed $sock"
1157 ::ftpd::Finish $sock
1159 #unset ::ftpd::$sock
1163 # ::ftpd::command::REIN --
1165 # Handle the REIN ftp command. This command terminates a USER, flushing
1171 # sock - The channel for this connection to the ftpd.
1172 # list - The arguments to the REIN command.
1181 proc ::ftpd::command::REIN {sock list} {
1182 upvar #0 ::ftpd::$sock data
1184 ::ftpd::FinishData $sock
1191 state command \
1193 cwd "$::ftpd::cwd" \
1201 # ::ftpd::command::RETR --
1203 # Handle the RETR ftp command. Gets a readable channel for the file
1204 # specified from ::ftpd::Fs and copies the file to second socket
1208 # sock - The channel for this connection to the ftpd.
1209 # list - The arguments to the RETR command.
1218 proc ::ftpd::command::RETR {sock filename} {
1219 upvar #0 ::ftpd::$sock data
1223 if {[::ftpd::hasCallback authFileCmd]} {
1224 set cmd $::ftpd::cfg(authFileCmd)
1235 if {![catch {::ftpd::Fs retr $path $data(mode)} f]} {
1237 fcopy $f $data(sock2) -command [list ::ftpd::GetDone $sock $data(sock2) $f ""]
1240 ::ftpd::FinishData $sock
1245 # ::ftpd::command::RMD --
1247 # Handle the RMD ftp command. Remove the specified directory.
1250 # sock - The channel for this connection to the ftpd.
1251 # list - The arguments to the RMD command.
1259 proc ::ftpd::command::RMD {sock filename} {
1260 upvar #0 ::ftpd::$sock data
1264 if {[::ftpd::hasCallback authFileCmd]} {
1265 set cmd $::ftpd::cfg(authFileCmd)
1272 if {[catch {::ftpd::Fs rmdir $path $sock} f]} {
1278 # ::ftpd::command::RNFR --
1280 # Handle the RNFR ftp command. Stores the name of the file to rename
1284 # sock - The channel for this connection to the ftpd.
1285 # list - The arguments to the RNFR command.
1294 proc ::ftpd::command::RNFR {sock filename} {
1295 upvar #0 ::ftpd::$sock data
1300 if {[::ftpd::hasCallback authFileCmd]} {
1301 set cmd $::ftpd::cfg(authFileCmd)
1317 # ::ftpd::command::RNTO --
1319 # Handle the RNTO ftp command. Renames the file specified by 'RNFR' if
1323 # sock - The channel for this connection to the ftpd.
1324 # list - The arguments to the RNTO command.
1332 proc ::ftpd::command::RNTO {sock filename} {
1333 upvar #0 ::ftpd::$sock data
1336 puts $sock "500 'RNTO': command not understood."
1346 if {[::ftpd::hasCallback authFileCmd]} {
1347 set cmd $::ftpd::cfg(authFileCmd)
1356 if {![catch {::ftpd::Fs rename $data(renameFrom) $path} msg]} {
1360 puts $sock "500 'RNTO': command not understood."
1365 # ::ftpd::command::SIZE --
1367 # Handle the SIZE ftp command. Prints the modification time of the
1371 # sock - The channel for this connection to the ftpd.
1372 # list - The arguments to the MDTM command.
1380 proc ::ftpd::command::SIZE {sock filename} {
1381 upvar #0 ::ftpd::$sock data
1384 if {[catch {::ftpd::Fs size $path $sock} msg]} {
1386 ::ftpd::FinishData $sock
1391 # ::ftpd::command::STOR --
1393 # Handle the STOR ftp command. Gets a writable channel for the file
1394 # specified from ::ftpd::Fs and copies the data from data(sock2) to
1398 # sock - The channel for this connection to the ftpd.
1399 # list - The arguments to the STOR command.
1408 proc ::ftpd::command::STOR {sock filename} {
1409 upvar #0 ::ftpd::$sock data
1412 if {[::ftpd::hasCallback authFileCmd]} {
1413 set cmd $::ftpd::cfg(authFileCmd)
1424 if {![catch {::ftpd::Fs store $path $data(mode)} f]} {
1426 fcopy $data(sock2) $f -command [list ::ftpd::GetDone $sock $data(sock2) $f ""]
1429 ::ftpd::FinishData $sock
1434 # ::ftpd::command::STOU --
1436 # Handle the STOR ftp command. Gets a writable channel for the file
1437 # specified from ::ftpd::Fs and copies the data from data(sock2) to
1441 # sock - The channel for this connection to the ftpd.
1442 # list - The arguments to the STOU command.
1451 proc ::ftpd::command::STOU {sock filename} {
1452 upvar #0 ::ftpd::$sock data
1455 if {[::ftpd::hasCallback authFileCmd]} {
1456 set cmd $::ftpd::cfg(authFileCmd)
1466 while {[::ftpd::Fs exists $file]} {
1474 if {![catch {::ftpd::Fs store $file $data(mode)} f]} {
1476 fcopy $data(sock2) $f -command [list ::ftpd::GetDone $sock $data(sock2) $f $file]
1479 ::ftpd::FinishData $sock
1484 # ::ftpd::command::SYST --
1486 # Handle the SYST ftp command. Print the system information.
1489 # sock - The channel for this connection to the ftpd.
1490 # list - The arguments to the SYST command.
1498 proc ::ftpd::command::SYST {sock list} {
1499 upvar #0 ::ftpd::$sock data
1518 # ::ftpd::command::TYPE --
1520 # Handle the TYPE ftp command. Sets up the proper translation mode on
1524 # sock - The channel for this connection to the ftpd.
1525 # list - The arguments to the TYPE command.
1534 proc ::ftpd::command::TYPE {sock type} {
1535 upvar #0 ::ftpd::$sock data
1550 # ::ftpd::command::USER --
1552 # Handle the USER ftp command. Store the username, and request a
1556 # sock - The channel for this connection to the ftpd.
1557 # list - The arguments to the USER command.
1565 proc ::ftpd::command::USER {sock username} {
1566 upvar #0 ::ftpd::$sock data
1575 ::ftpd::Log debug "user <$data(user)>"
1579 # ::ftpd::GetDone --
1581 # The fcopy command callback for both the RETR and STOR calls. Called
1585 # sock - The channel for this connection to the ftpd.
1601 proc ::ftpd::GetDone {sock sock2 f filename bytes {err {}}} {
1602 upvar #0 ::ftpd::$sock data
1622 # ::ftpd::List --
1624 # Handle the NLST and LIST ftp commands. Shared command to do the
1628 # sock - The channel for this connection to the ftpd.
1638 proc ::ftpd::List {sock filename style} {
1639 upvar #0 ::ftpd::$sock data
1653 # ftpd.
1655 namespace eval ::ftpd::fsFile {
1666 # ::ftpd::fsFile::docRoot --
1668 # Set or query the root of the ftpd file system. If no 'dir' argument
1685 proc ::ftpd::fsFile::docRoot {{dir {}}} {
1695 # ::ftpd::fsFile::fs --
1701 # command - The filesystem command (one of dlist, retr, or
1725 # callback configured for the ftpd.
1727 proc ::ftpd::fsFile::fs {command path args} {
1747 switch -exact -- $command {
1780 ::ftpd::Log debug "at dlist {$style} {$outchan} {$path}"
1782 #::ftpd::Log debug "at dlist2 {$style} {$outchan} {$path}"
1799 ::ftpd::Log debug "File list is {$fileList}"
1803 ::ftpd::Log debug "In nlist"
1810 ::ftpd::Log debug [file tail $f]
1851 puts $outchan "250 DELE command successful."
1901 puts $sock "250 RNTO command successful."
1912 puts $outchan "250 RMD command successful."
1927 error "Unknown command \"$command\""
1933 # ::ftpd::fsFile::PermBits --
1946 proc ::ftpd::fsFile::PermBits {file mode} {
1965 # ::ftpd::fsFile::FormDate --
1978 proc ::ftpd::fsFile::FormDate {seconds} {
1998 package provide ftpd 1.2.5
2003 ## Implementation of passive command
2005 proc ::ftpd::command::PASV {sock argument} {
2006 upvar #0 ::ftpd::$sock data
2008 set data(sock2a) [socket -server [list ::ftpd::PasvAccept $sock] 0]
2013 ::ftpd::Log debug "PASV on {$list1} {$list2} $ip $port"
2023 proc ::ftpd::PasvAccept {sock sock2 ip port} {
2024 upvar #0 ::ftpd::$sock data
2026 ::ftpd::Log debug "In Pasv Accept with {$sock} {$sock2} {$ip} {$port}"
2037 ::ftpd::FinishData $sock