ftp(3tcl)
β¨ ftp β the Tcl ftp client, bestie edition β¨
okay so this is ftp(3tcl), the ftp client page, and we're gonna get through it together π
π NAME π
ftp β client-side tcl implementation of the ftp protocol
π¦ SYNOPSIS π¦
package require Tcl 8.5 9
package require ftp ?2.4.14?
::ftp::Open server user passwd ?options?
::ftp::Close handle
::ftp::Cd handle directory
::ftp::Pwd handle
::ftp::Type handle ?ascii|binary|tenex?
::ftp::List handle ?pattern?
::ftp::NList handle ?directory?
::ftp::FileSize handle file
::ftp::ModTime handle file
::ftp::Delete handle file
::ftp::Rename handle from to
::ftp::Put handle (local | -data data | -channel chan) ?remote?
::ftp::Append handle (local | -data data | -channel chan) ?remote?
::ftp::Get handle remote ?(local | -variable varname | -channel chan)?
::ftp::Reget handle remote ?local? ?from? ?to?
::ftp::Newer handle remote ?local?
::ftp::MkDir handle directory
::ftp::RmDir handle directory
::ftp::Quote handle arg1 arg2 ...
::ftp::DisplayMsg handle msg ?state?
π DESCRIPTION π
So the ftp package is giving client side of the ftp protocol, exactly like RFC 959 says (that's http://www.rfc-editor.org/rfc/rfc959.txt if you wanna read the lore). And it does both active (which is the default, no cap) and passive ftp sessions. versatile queen π
You start a brand new ftp session with ::ftp::Open, and when you're done you shut it down with ::ftp::Close. Every single other command? They're only allowed inside an open ftp session. Use them out of context and they will literally generate errors at you π. The package also comes with file and directory manipulating commands for remote sites β and if you wanna do the same stuff on your local site, just use the commands built into the core, like cd or file. local business stays local β¨
Now, the output of the package is controlled by two state variables, ::ftp::VERBOSE and ::ftp::DEBUG. Here's the vibe check:
- Set
::ftp::VERBOSEto"1"and the package is forced to show you all responses from a remote server. The default value is"0". - Set
::ftp::DEBUGto"1"and debugging is enabled, which forces the package to show all return codes, states, state changes and"real"ftp commands. The default value is"0".
The command ::ftp::DisplayMsg is the one showing the different messages from the ftp session. Whether it gets called at all depends on the setting of ::ftp::VERBOSE. The current implementation of the command uses the log package of tcllib to write the messages to their final destination β which means the behaviour of ::ftp::DisplayMsg can be customized without changing its implementation. obsessed. And for more radical changes, overwriting its implementation by the application is of course still possible. Note that the default implementation honors the option -output to ::ftp::Open for a session specific log command π
β οΈ Caution: the default implementation logs error messages like all other messages. If this behaviour is changed to throwing an error instead, all commands in the API will change their behaviour too. In such a case they will not return a failure code as described below but pass the thrown error to their caller. so likeβ¦ be aware bestie π
π API π
π«Ά ::ftp::Open server user passwd ?options?
This command is how you start a FTP session β it establishes a control connection to the FTP server. Any option you don't specify by hand just gets the defaults. no stress.
It takes a host name server, a user name user and a password password as its parameters, and it returns a session handle that is an integer number greater than or equal to "0" if the connection is successfully established. Otherwise it returns "-1" π. The server parameter must be the name or internet address (in dotted decimal notation) of the ftp server to connect to. The user and passwd parameters must contain a valid user name and password to complete the login process. periodt.
The options overwrite some default values or set special abilities:
-blocksizesize β the blocksize is used during data transfer. At most size bytes are transfered at once. The default value for this option is4096. The package will evaluate the-progresscallback for the session after the transfer of each block. little chunks, big vibes π-timeoutseconds β if seconds is non-zero, then::ftp::Opensets up a timeout which will occur after the specified number of seconds. The default value is600.-portnumber β the port number specifies an alternative remote port on the ftp server on which the ftp service resides. Most ftp services listen for connection requests on the default port21. Sometimes, usually for security reasons, port numbers other than21are used for ftp connections.-modemode β the transfer mode option determines if a file transfer occurs in active or passive mode. In passive mode the client will ask the ftp server to listen on a data port and wait for the connection rather than to initiate the process by itself when a data transfer request comes in. Passive mode is normally a requirement when accessing sites via a firewall. The default mode is active.-progresscallback β this callback is evaluated whenever a block of data was transfered. See the option-blocksizefor how to specify the size of the transfered blocks.
When evaluating the callback, one argument is appended to the callback script: the current accumulated number of bytes transferred so far. live updates, main character energy β
-commandcallback β specifying this option places the connection into asynchronous mode. The callback is evaluated after the completion of any operation. When an operation is running, no further operations must be started until a callback has been received for the currently executing operation. one at a time, bestie, one at a time π§
When evaluating the callback, several arguments are appended to the callback script, namely the keyword of the operation that has completed and any additional arguments specific to the operation. If an error occurred during the execution of the operation, the callback is given the keyword error.
-outputcallback β this option has no default. If it is set, the default implementation of::ftp::DisplayMsgwill use its value as command prefix to log all internal messages. The callback will have three arguments appended to it before evaluation: the id of the session, the message itself, and the connection state, in this order. order matters, always π
π ::ftp::Close handle
This command terminates the specified ftp session. If no file transfer is in progress, the server will close the control connection immediately. If a file transfer is in progress however, the control connection will remain open until the transfer completes. When that happens the server will write the result response for the transfer to it and close the connection afterward. so patient. so elegant. πΈ
π¦ ::ftp::Cd handle directory
This command changes the current working directory on the ftp server to a specified target directory. It returns 1 if the current working directory was successfully changed to the specified directory, or 0 if it fails. The target directory can be
- a subdirectory of the current directory,
- Two dots,
..(as an indicator for the parent directory of the current directory), - or a fully qualified path to a new working directory.
β¨ ::ftp::Pwd handle
This command returns the complete path of the current working directory on the ftp server, or an empty string in case of an error. where am i?? πΊοΈ
π ::ftp::Type handle ?ascii|binary|tenex?
This command sets the ftp file transfer type to either ascii, binary, or tenex. The command always returns the currently set type. If called without type, no change is made. no notes.
Currently only ascii and binary types are supported. There is some early (alpha) support for Tenex mode. The type ascii is normally used to convert text files into a format suitable for text editors on the platform of the destination machine β this mainly affects end-of-line markers. The type binary on the other hand allows the undisturbed transfer of non-text files, such as compressed files, images and executables. pick your fighter π
π ::ftp::List handle ?pattern?
This command returns a human-readable list of files. Wildcard expressions such as "*.tcl" are allowed. If pattern refers to a specific directory, then the contents of that directory are returned. If the pattern is not a fully-qualified path name, the command lists entries relative to the current remote directory. If no pattern is specified, the contents of the current remote directory is returned.
The listing includes any system-dependent information that the server chooses to include. For example most UNIX systems produce output from the command ls -l. The command returns the retrieved information as a tcl list with one item per entry. Empty lines and UNIX's "total" lines are ignored and not included in the result as reported by this command. we love a clean list π§Ήβ¨
If the command fails an empty list is returned.
π ::ftp::NList handle ?directory?
This command has the same behavior as the ::ftp::List command, except that it only retrieves an abbreviated listing. This means only file names are returned in a sorted list. names only, no extras, minimalism ate π₯
π ::ftp::FileSize handle file
This command returns the size of the specified file on the ftp server. If the command fails an empty string is returned.
β οΈ ATTENTION! It will not work properly when in ascii mode and is not supported by all ftp server implementations. so like, don't come for me if it ghosts you π
πΈ ::ftp::ModTime handle file
This command retrieves the time of the last modification of the file on the ftp server as a system dependent integer value in seconds, or an empty string if an error occurred. Use the built-in command clock to convert the retrieved value into other formats. time travel but make it timestamped β°
πΈ ::ftp::Delete handle file
This one deletes the file you point at on the ftp server. That's it, that's the whole job. It hands back 1 if the file got successfully yeeted into the void, or 0 if it didn't. π
π ::ftp::Rename handle from to
Renames the file from in the current directory of the ftp server to the shiny new file name to. Bestie, heads up: this new name must not be the same as any existing subdirectory or file name, okay? No identity theft in this house. π
ββοΈ Returns 1 if the rename slayed, or 0 if it flopped.
π ::ftp::Put handle (local | -data data | -channel chan) ?remote?
Transfers a local file local to a remote file remote on the ftp server. If the file parameters you pass aren't fully qualified path names, the command will just use the current directory on both the local and remote host. And if you don't specify the remote file name? The server will use the name of the local file as the name of the remote file. Convenient! It returns 1 to indicate a successful transfer and 0 in the case of a failure.
If -data data is specified instead of a local file, the system won't transfer a file at all β it'll transfer the data you passed in. In this case the name of the remote file has to be specified. No skipping.
If -channel chan is specified instead of a local file, the system won't transfer a file either β it reads the contents of the channel chan and writes this to the remote file. Again, the name of the remote file has to be specified. After the transfer, chan will be closed. β¨
π¦ ::ftp::Append handle (local | -data data | -channel chan) ?remote?
This command behaves like ::ftp::Puts, but appends the transfered information to the remote file instead of overwriting the whole thing. And if the file didn't exist on the server, it will be created. Iconic, honestly. π
π ::ftp::Get handle remote ?(local | -variable varname | -channel chan)?
Retrieves a remote file remote on the ftp server and stores its contents into the local file local. If the file parameters you pass aren't fully qualified path names, the command will use the current directory on the local and remote host. If you don't specify the local file name, the server will use the name of the remote file as the name of the local file. Returns 1 to indicate a successful transfer and 0 in the case of a failure. Also, it will throw an error if the directory the file local is to be placed in does not exist. π
If -variable varname is specified, the system will store the retrieved data into the variable varname instead of a file. So no file, just vibes in a variable.
If -channel chan is specified, the system will write the retrieved data into the channel chan instead of a file. And listen β the system will not close chan after the transfer. That's the responsibility of the caller to ::ftp::Get. You break it, you bought it. π«Ά
π ::ftp::Reget handle remote ?local? ?from? ?to?
This command behaves like ::ftp::Get, except that if local file local exists and is smaller than remote file remote, the local file is presumed to be a partially transferred copy of the remote file and the transfer is continued from the apparent point of failure. It'll throw an error if the directory the file local is to be placed in does not exist. This one is so useful when transferring very large files over networks that tend to drop connections. Resilient queen behavior. π
Specifying the additional byte offsets from and to will cause the command to change its behaviour and download exactly the specified slice of the remote file. This mode is possible only if a local destination is explicitly provided. Omission of to leads to downloading till the end of the file.
β¨ ::ftp::Newer handle remote ?local?
This command behaves like ::ftp::Get, except that it retrieves the remote file only if the modification time of the remote file is more recent than the file on the local system. If the file does not exist on the local system, the remote file is considered newer. It'll throw an error if the directory the file local is to be placed in does not exist. It's giving "only if it's fresh." π
πΈ ::ftp::MkDir handle directory
Creates the specified directory on the ftp server. If the specified path is relative, the new directory will be created as a subdirectory of the current working directory. Else the created directory will have the specified path name. Returns 1 to indicate a successful creation of the directory and 0 in the case of a failure.
π§ ::ftp::RmDir handle directory
Removes the specified directory on the ftp server. The remote directory has to be empty or the command will fail. No clutter allowed, bestie. Returns 1 to indicate a successful removal of the directory and 0 in the case of a failure.
π₯ ::ftp::Quote handle arg1 arg2 ...
This command is used to send an arbitrary ftp command to the server. It cannot be used to obtain a directory listing or for transferring files. It's included to allow an application to execute commands on the ftp server which are not provided by this package. The arguments are sent verbatim, i.e. as is, with no changes. Raw. Unfiltered. π€
In contrast to the other commands in this package, this command will not parse the response it got from the ftp server but return it verbatim to the caller.
π ::ftp::DisplayMsg handle msg ?state?
This command is used by the package itself to show the different messages from the ftp sessions. The package itself declares this command very simple, writing the messages to stdout (if ::ftp::VERBOSE was set, see below) and throwing tcl errors for error messages. It is the responsibility of the application to overwrite it as needed. A state variable for different states assigned to different colors is recommended by the author. The package log is useful for this.
π ::ftp::VERBOSE
A state variable controlling the output of the package. Setting ::ftp::VERBOSE to "1" forces the package to show all responses from a remote server. The default value is "0".
π ::ftp::DEBUG
A state variable controlling the output of ftp. Setting ::ftp::DEBUG to "1" enables debugging and forces the package to show all return codes, states, state changes and "real" ftp commands. The default value is "0".
π BUGS
The correct execution of many commands depends upon the proper behavior by the remote server, network and router configuration. Basically, it's not always us, sometimes it's the network. π
An update command placed in the procedure ::ftp::DisplayMsg may run into persistent errors or infinite loops. The solution to this problem is to use update idletasks instead of update. Save yourself the spiral, bestie.
π«Ά BUGS, IDEAS, FEEDBACK
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category ftp 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.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
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.
π SEE ALSO
ftpd, mime, pop3, smtp
β KEYWORDS
ftp, internet, net, rfc 959
π CATEGORY
Networking
And that's a wrap on the wholeftp(3tcl)page, bestie! This masterpiece comes from tcllib version2.4.14. Go forth and transfer files responsibly. π β¨π¦
π¦ 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