ftpd(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸŽ€ 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. myaddr is 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 ...? β€” the value is always the name of the command to call as the callback. the option says which callback should be configured. for what each callback's arguments and return values look like, go read the CALLBACKS section. πŸ’Œ
    • -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 user's password). πŸ”
    • -authFileCmd proc β€” callback to accept or deny a user's 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 is the one that lets the embedding application do its own cleanup operations. bye bye, tidy girl. 🧹
    • -xferDoneCmd proc β€” 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 β€” the append subcommand receives the filename to append to as its argument. it returns a writable tcl channel as its return value. ✍️
  • 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 gets deleted, and the appropriate ftp message is written to the channel that was passed as the second argument. the delete subcommand returns nothing. πŸ—‘οΈ
  • fsCmd dlist path style channel β€” the dlist subcommand receives three arguments: the path 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. 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 gets printed to the channel. if the style is list, 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. the dlist subcommand returns nothing. πŸ“‹
  • 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. πŸ”
  • 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 it's necessary and possible. then it 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. 🧾
  • 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. πŸ”
  • 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. πŸ“–
  • 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. πŸ’Ύ

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:

  1. the channel handle of the control socket for the connection
  2. the channel handle of the data socket used for the transfer (already closed)
  3. the handle of the channel containing the transferred file
  4. the number of bytes transferred
  5. the path of the file which was transferred
  6. 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 the REIN ftp 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 FTP HELP command. yes literally, random people can HELP and 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