ftpd(n)
π ftpd β the Tcl FTP Server Package π
okay bestie, sit down, hydrate, because we're about to make a whole FTP server in Tcl and it's gonna be iconic. this is the ftpd(n) manual page, part 1 of 2, so don't go anywhere when you hit the bottom π«Ά
β¨ NAME β¨
ftpd β Tcl FTP server implementation
like, literally the name says it all. it's an FTP server. in Tcl. she's serving π
πΈ 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
the?question marks?mean "optional, girl, you can skip it". the barefsCmd ...lines are the subcommands your own filesystem callback has to handle β more on that in a sec π§
π¦ DESCRIPTION π¦
so the ftpd package is a simple, Tcl-only server library for the FTP protocol, exactly as specified in RFC 959 (<http://www.rfc-editor.org/rfc/rfc959.txt>). no C extensions, no compiled anything, just vibes and Tcl. she works by listening on the standard FTP socket π
most server errors come back as error messages with the appropriate code attached to them β so if something goes wrong, the code is riding along with the message, no cap.
and here's the tea: since the server code for the ftp daemon runs inside the event loop, it's possible that a bgerror will get thrown on the server if there are problems with the code in the module. so likeβ¦ write good callbacks, bestie π
π COMMANDS π
::ftpd::server ?myaddr?
opens a listening socket to listen to and accept ftp connections. she's the bouncer at the door fr fr.
myaddr is an optional argument β it's the domain-style name or numerical IP address of the client-side network interface to use for the connection. so if you've got multiple network interfaces and you're feeling picky about which one, that's your moment β¨
::ftpd::config ?option value? ?option value ...?
the value is always the name of the command to call as the callback. the option specifies which callback should be configured. peek the CALLBACKS section below for the deets on arguments and return values for each one π
-authIpCmd procβ callback to authenticate new connections based on the ip-address of the peer.-authUsrCmd procβ callback to authenticate new connections based on the user logging in (and the users password).-authFileCmd procβ callback to accept or deny a users access to read and write to a specific path or file.-logCmd procβ callback for log information generated by the FTP engine.-fsCmd procβ callback to connect the engine to the filesystem it operates on.-closeCmd procβ callback to be called when a connection is closed. this allows the embedding application to perform its own cleanup operations π§Ή-xferDoneCmd procβ callback for transfer completion notification. in other words, it is 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 the specified IP to attempt to login, and a 0 to reject the login attempt from the specified IP. gatekeeping, but make it authorized π
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. yes girl, you get to decide who's in the group chat π
authFileCmd callback
the authFileCmd receives three arguments: the user (that is currently logged in), the path or filename that is about to be read or written, and read or write.
it returns a 1 to allow the path or filename to be read or written, and a 0 to reject the attempted read or write with a permissions error code. so this is where you play favorites with your filesystem, periodt π
logCmd callback
the logCmd receives a severity and a message as its two arguments.
the severities used within the ftpd package are note, debug, and error. those three, exactly, no extras.
the logCmd doesn't return anything. it's a listener, not a talker π
fsCmd callback
the fsCmd receives a subcommand, a filename or path, and optional additional arguments (depending on the subcommand).
the subcommands supported by the fsCmd are:
fsCmd append path
the append subcommand receives the filename to append to as its argument.
it returns a writable tcl channel as its return value. go off, write your little heart out βοΈ
fsCmd delete path channel
the delete subcommand receives the filename to delete, and a channel to write to as its two arguments.
the file specified is deleted and the appropriate ftp message is written to the channel that is passed as the second argument.
the delete subcommand returns nothing. gone, reduced to atoms π
fsCmd dlist path style channel
the dlist subcommand receives the path that it should list the files that are in, the style in which the files should be listed (which is either nlst or list), and a channel to write to as its three arguments.
the files in the specified path are printed to the specified channel one per line.
if the style is nlst, only the name of the file is printed to the channel.
if the style is list, then the following get 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
- the filename
the dlist subcommand returns nothing. it just yaps into the channel, and honestly? valid π
fsCmd exists path
the exists subcommand receives the name of a file to check the existence of as its only argument.
the exists subcommand returns a 1 if the path specified exists and the path is not a directory. note that second part bestie, directories don't count here β οΈ
fsCmd mkdir path channel
the mkdir subcommand receives the path of a directory to create and a channel to write to as its two arguments.
the mkdir subcommand creates the specified directory if necessary and possible. it then prints the appropriate success or failure message to the channel.
the mkdir subcommand returns nothing ποΈ
fsCmd mtime path channel
the mtime subcommand 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.
the mtime subcommand returns nothing β°
fsCmd permissions path
the permissions subcommand receives the path of a file to retrieve the permissions of.
the permissions subcommand returns the octal file permissions of the specified file.
the file is expected to exist. so like, don't come crying to her if it doesn't π
fsCmd rename path newpath channel
the rename subcommand receives the path of the current file, the new file path, and a channel to write to as its three arguments.
the rename subcommand 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.
the rename subcommand returns nothing. glow-up complete, new name, same file π
fsCmd retr path
the retr subcommand receives the path of a file to read as its only argument.
the retr subcommand returns a readable channel that the specified file can be read from. come get your data π
fsCmd rmdir path channel
the rmdir subcommand receives the path of a directory to remove and a channel to write to as its two arguments.
the rmdir subcommand 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.
the rmdir subcommand returns nothing ποΈ
fsCmd size path channel
the size subcommand receives the path of a file to get the size (in bytes) of and a channel to write to as its two arguments.
the size subcommand 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.
the size subcommand returns nothing π
fsCmd store path
the store subcommand receives the path of a file to write as its only argument.
the store subcommand returns a writable channel. that's it, that's the whole thing, she's simple and she knows it β¨
closeCmd
the closeCmd receives no arguments when it is invoked, and any return value it may generate is discarded.
so like, do your cleanup, but nobody's reading your receipts π§Ό
xferDoneCmd sock sock2 file bytes filename err
the xferDoneCmd receives six arguments when invoked. these are, in this order:
- 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 transfered file
- the number of bytes transfered
- the path of the file which was transfered
- a (possibly empty) error message
any return value it may generate is discarded.
so this is your little end-of-transfer victory lap callback π and yes, bestie, the original really does spell it "transfered" both times β we keep the facts exactly as they are, always π
part 1 done!! don't leave yet, there's more of this page coming β stay tuned, same server, same vibes π«Ά
π¦ VARIABLES π¦
Okay bestie, these are the global variables that run the whole vibe of your ftpd session. They're not options you pass on the command line β they're the knobs the server reads. Don't touch them unless you know what you're doing, but here's what each one means. π
::ftpd::cwdβ the current working directory for a session when someone first connects to the FTPD, or when theREINftp command is received. It's giving "where you start your little FTP journey." π::ftpd::contactβ the e-mail address of the person who's the contact for the ftp server. This address gets printed out as part of the response to the FTPHELPcommand. So when someone types HELP, your email pops up like "hi, I'm the problem, it's me." π§::ftpd::portβ the port the ftp server should listen on. If port is specified aszero, 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 zero = "surprise me, OS bestie." π²::ftpd::welcomeβ the message that is printed out when the user first connects to the ftp server. Your grand entrance. Your "welcome to my crib" moment. π‘β¨::ftpd::CurrentSocketβ accessible to all callbacks and all filesystem commands (which are a special form of callback), and contains the handle of the socket channel which was active when the callback was invoked. Basically it's like "which socket are we on right now?" β very main character energy. π
π BUGS, IDEAS, FEEDBACK π
Not to be dramatic, but this document and the package it describes will undoubtedly contain bugs and other problems. It's not a vibe, it's just software. π Please report such in the category ftpd of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation. We love a glow-up suggestion. π«Ά
When proposing code changes, please provide unified diffs, i.e the output of diff -u. That's the love language of maintainers. π
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. No cap, that's the way. π
π KEYWORDS π
ftp, ftpd, ftpserver, rfc 959, services
π CATEGORY π
Networking
Okay bye bestie! π The footer on this one says source tcllib, version 1.4.1, and it's the ftpd(n) manual β the date slot is literally blank, so we're just vibing with the version. Slay. β¨π¦
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms