ftpd(3tcl)
π ftpd(3tcl) π
okay bestie, welcome to ftpd β the Tcl FTP Server Package, and yes she's a real one. this is ftpd(3tcl), no cap. π
β¨ NAME β¨
ftpd β a whole Tcl FTP server implementation. she's serving, literally. π
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require ftpd ?1.4.1?
::ftpd::server ?myaddr?
::ftpd::config ?option value? ?option value ...?
fsCmd append path
fsCmd delete path channel
fsCmd dlist path style channel
fsCmd exists path
fsCmd mkdir path channel
fsCmd mtime path channel
fsCmd permissions path
fsCmd rename path newpath channel
fsCmd retr path
fsCmd rmdir path channel
fsCmd size path channel
fsCmd store path
π¦ DESCRIPTION π¦
so the ftpd package is a simple, Tcl-only server library for the FTP protocol, exactly as it's specified in RFC 959 (http://www.rfc-editor.org/rfc/rfc959.txt). it does its thing by listening on the standard FTP socket. icon behaviour. π
most server errors come back at you as error messages with the appropriate code attached to them β so the code rides along with the message, iykyk.
and now the part where you go "not me getting jumpscared by this": since the server code for the ftp daemon runs inside the event loop, it's possible that a bgerror gets thrown on the server if there are problems with the code in the module. so like, mind your module code, bestie. π«Ά
π COMMANDS π
::ftpd::server ?myaddr?β opens a listening socket to listen to and accept ftp connections.myaddris optional, and it's the domain-style name or numerical IP address of the client-side network interface to use for the connection. pick your interface, main character energy. β¨::ftpd::config ?option value? ?option value ...?β thevalueis always the name of the command to call as the callback. theoptionsays which callback should be configured. for what each callback's arguments and return values look like, go read the CALLBACKS section. π-authIpCmdproc β callback to authenticate new connections based on the ip-address of the peer. π-authUsrCmdproc β callback to authenticate new connections based on the user logging in (and the user's password). π-authFileCmdproc β callback to accept or deny a user's access to read and write to a specific path or file. π-logCmdproc β callback for log information generated by the FTP engine. π-fsCmdproc β callback to connect the engine to the filesystem it operates on. ποΈ-closeCmdproc β callback to be called when a connection is closed. this is the one that lets the embedding application do its own cleanup operations. bye bye, tidy girl. π§Ή-xferDoneCmdproc β callback for transfer completion notification. in other words, it gets called whenever a transfer of data to or from the client has completed. π
π CALLBACKS π
authIpCmd callback
the authIpCmd receives the ip-address of the peer attempting to connect to the ftp server as its argument. it returns a 1 to allow users from that specified IP to attempt to login, and a 0 to reject the login attempt from that specified IP. so basically: 1 = come in, 0 = not today. πͺ
authUsrCmd callback
the authUsrCmd receives the username and password as its two arguments. it returns a 1 to accept the attempted login to the ftpd, and a 0 to reject the attempted login. π΅οΈβοΈ
authFileCmd callback
the authFileCmd receives three arguments: the user (the one that's currently logged in), the path or filename that's about to be read or written, and read or write. it returns a 1 to allow that path or filename to be read or written, and a 0 to reject the attempted read or write with a permissions error code. π«
logCmd callback
the logCmd receives a severity and a message as its two arguments. the severities used inside the ftpd package are note, debug, and error. the logCmd doesn't return anything. quiet queen, she just listens. π
fsCmd callback
the fsCmd receives a subcommand, a filename or path, and optional additional arguments β the extras depend on which subcommand it is. π«§
the subcommands that fsCmd supports are:
fsCmd append pathβ theappendsubcommand receives the filename to append to as its argument. it returns a writable tcl channel as its return value. βοΈfsCmd delete path channelβ thedeletesubcommand receives the filename to delete, and a channel to write to, as its two arguments. the file specified gets deleted, and the appropriate ftp message is written to the channel that was passed as the second argument. thedeletesubcommand returns nothing. ποΈfsCmd dlist path style channelβ thedlistsubcommand receives three arguments: the path it should list the files that are in, the style in which the files should be listed (which is eithernlstorlist), and a channel to write to. the files in the specified path are printed to the specified channel, one per line. if the style isnlst, only the name of the file gets printed to the channel. if the style islist, then all of this gets printed out to the channel in a formatted, space separated format: the file permissions, the number of links to the file, the name of the user that owns the file, the name of the group that owns the file, the size (in bytes) of the file, the modify time of the file, and the filename. thedlistsubcommand returns nothing. πfsCmd exists pathβ theexistssubcommand receives the name of a file to check the existence of as its only argument. theexistssubcommand returns a1if the path specified exists and the path is not a directory. πfsCmd mkdir path channelβ themkdirsubcommand receives the path of a directory to create and a channel to write to, as its two arguments. themkdirsubcommand creates the specified directory if it's necessary and possible. then it prints the appropriate success or failure message to the channel. themkdirsubcommand returns nothing. ποΈfsCmd mtime path channelβ themtimesubcommand receives the path of a file to check the modify time on, and a channel, as its two arguments. if the file exists, the mtime is printed to the channel in the proper FTP format. otherwise, an appropriate error message and code are printed to the channel. themtimesubcommand returns nothing. β°fsCmd permissions pathβ thepermissionssubcommand receives the path of a file to retrieve the permissions of. thepermissionssubcommand returns the octal file permissions of the specified file. the file is expected to exist. π§ΎfsCmd rename path newpath channelβ therenamesubcommand receives the path of the current file, the new file path, and a channel to write to, as its three arguments. therenamesubcommand renames the current file to the new file path if the path to the new file exists, and then prints out the appropriate message to the channel. if the new file path doesn't exist, the appropriate error message is printed to the channel. therenamesubcommand returns nothing. πfsCmd retr pathβ theretrsubcommand receives the path of a file to read as its only argument. theretrsubcommand returns a readable channel that the specified file can be read from. πfsCmd rmdir path channelβ thermdirsubcommand receives the path of a directory to remove and a channel to write to, as its two arguments. thermdirsubcommand removes the specified directory (if possible) and prints the appropriate message to the channel β which may be an error if the specified directory does not exist or is not empty. thermdirsubcommand returns nothing. π₯fsCmd size path channelβ thesizesubcommand receives the path of a file to get the size (in bytes) of, and a channel to write to, as its two arguments. thesizesubcommand prints the appropriate code and the size of the file if the specified path is a file. otherwise, an appropriate error code and message are printed to the channel. thesizesubcommand returns nothing. πfsCmd store pathβ thestoresubcommand receives the path of a file to write as its only argument. thestoresubcommand returns a writable channel. πΎ
closeCmd
the closeCmd receives no arguments when it's invoked, and any return value it may generate is discarded. she takes nothing, gives nothing. iconic. π
xferDoneCmd sock sock2 file bytes filename err
the xferDoneCmd receives six arguments when invoked. in this order, bestie:
- the channel handle of the control socket for the connection
- the channel handle of the data socket used for the transfer (already closed)
- the handle of the channel containing the transferred file
- the number of bytes transferred
- the path of the file which was transferred
- a (possibly empty) error message
any return value it may generate is discarded. π
π¦ VARIABLES π¦
okay bestie so before we get into the drama, these are the global variables that control how your whole ftpd situation looks and feels. set them, love them, respect them π
::ftpd::cwdβ this is the current working directory for a session β specifically, the dir someone lands in when they first connect to the FTPD, and also the dir you get dumped into when theREINftp command shows up. so like, the starting room of the house π::ftpd::contactβ the e-mail address of the person who is the contact for the ftp server. this address gets printed out as part of the response to the FTPHELPcommand. yes literally, random people canHELPand see your email, so put one you actually check π::ftpd::portβ the port that the ftp server should listen on. now here's the cute part: if port is specified as zero, the operating system will allocate an unused port for use as a server socket; afterwards, the variable will contain the port number that was allocated. so it's giving "you pick for me bestie" and then it tells you what it picked β¨::ftpd::welcomeβ the message that is printed out when the user first connects to the ftp server. this is your moment. your main character entrance. make it iconic π::ftpd::CurrentSocketβ accessible to all callbacks and all filesystem commands (which are a special form of callback), and it contains the handle of the socket channel which was active when the callback was invoked. so if you ever need to know "wait, who am I even talking to rn", this variable has the answer π
π BUGS, IDEAS, FEEDBACK π
okay so real talk. this document, and the package it describes, will undoubtedly contain bugs and other problems. not me being self-aware but also honest. so please report such in the category ftpd of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. don't be shy, the tracker is literally right there π«Ά
also please report any ideas for enhancements you may have for either package and/or documentation. we want them. all of them. no gatekeeping π
When proposing code changes, please provide unified diffs, i.e the output of diff -u. that's the vibe. that's the format. periodt π
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. yep, the left-most one. the little guy on the far left. that's your button πΈ
fr fr: inline patches are the situationship nobody asked for. attach the file. it's cleaner, it's kinder, it's the move π
π KEYWORDS π
ftp, ftpd, ftpserver, rfc 959, services
π CATEGORY π
Networking
and that's the whole page bestie, you ate it, you read the whole thing, i'm so proud of you π
this was ftpd(3tcl) from tcllib, version 1.4.1 β go forth and serve some files, you absolute icon βπ¦
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms