PaiGack/ftp/core does not have a README file

    FtpError

    pub(all) suberror FtpError {
    ServerError(code~ : Int, msg~ : String)
    InvalidCommand(arg~ : String)
    UnsupportedListLine(line~ : String)
    UnsupportedListDate(field~ : String)
    ParseError(msg~ : String)
    RequestTimeout
    } derive(
    Debug
    )

    Error type for every failure that is produced by the FTP protocol layer itself (as opposed to failures raised by the underlying IO stack, which bubble up untouched so callers can still inspect the OS error).

    FtpError::to_repr

    FtpError promotes its Debug methods as regular methods; declare the promotion explicitly so the deprecation warning stays away.

    FtpErrors

    pub(all) suberror FtpErrors {
    MultipleErrors(errors~ : Array[Error])
    } derive(
    Debug
    )

    Aggregation of several failures that happened during one logical operation. This mirrors Go's errors.Join: the upstream implementation deliberately keeps every error (transfer + close + status read) instead of returning as soon as the first one shows up.

    FtpErrors::to_repr

    FtpErrors promotes its Debug methods as regular methods; declare the promotion explicitly so the deprecation warning stays away.

    Entry

    pub struct Entry {
    name : String
    target : String
    type_ : EntryType
    size : UInt64
    time :
    ZonedDateTime

    } derive(
    Debug
    )

    A single remote directory entry.

    Mirroring upstream ftp.Entry:
    • target is empty for non-symlinks (Go zero value semantics),
    • time carries an explicit timezone because LIST timestamps are wall-clock time in the server's timezone.

    Entry::set_name

    fn Entry::set_name(self : Entry, name : String) -> Unit

    Replace the name of an entry in place.

    Entry::set_size

    fn Entry::set_size(self : Entry, size : UInt64) -> Unit

    Replace the size of an entry in place.

    Entry::set_target

    fn Entry::set_target(self : Entry, target : String) -> Unit

    Replace the symlink target of an entry in place.

    Entry::set_time

    fn Entry::set_time(self : Entry, time :
    ZonedDateTime
    ) -> Unit

    Replace the modification time of an entry in place.

    Entry::set_type

    fn Entry::set_type(self : Entry, type_ : EntryType) -> Unit

    Replace the kind of an entry in place.

    Entry::to_repr

    Entry promotes its Debug methods as regular methods; declare the promotion explicitly so the deprecation warning stays away.

    EntryType

    pub(all) enum EntryType {
    File
    Folder
    Link
    } derive(Eq,
    Debug
    )

    The kind of a remote directory entry, mirroring upstream ftp.EntryType.

    EntryType::equal

    fn EntryType::equal(EntryType, EntryType) -> Bool

    EntryType promotes its Eq and Debug methods as regular methods; declare the promotions explicitly so the deprecation warning stays away.

    EntryType::not_equal

    fn EntryType::not_equal(x : EntryType, y : EntryType) -> Bool

    EntryType promotes its Eq and Debug methods as regular methods; declare the promotions explicitly so the deprecation warning stays away.

    EntryType::to_string

    fn EntryType::to_string(self : EntryType) -> String

    Return the lowercase name of the entry type, matching the string form used by the Go implementation (file / folder / link).

    ListDateField

    type ListDateField

    The pieces of a LIST date field: MMM is consumed by the caller.

    ListDateField::day

    fn ListDateField::day(self : ListDateField) -> Int

    The day of month of a parsed date field.

    ListDateField::has_time

    fn ListDateField::has_time(self : ListDateField) -> Bool

    Whether the field used the yearless HH:MM shape.

    ListDateField::hour

    fn ListDateField::hour(self : ListDateField) -> Int

    The hour, 0 when the field carried none.

    ListDateField::minute

    fn ListDateField::minute(self : ListDateField) -> Int

    The minute, 0 when the field carried none.

    ListDateField::next

    fn ListDateField::next(self : ListDateField) -> Int

    The index right after the parsed date field.

    ListDateField::year

    fn ListDateField::year(self : ListDateField) -> Int

    The year of a parsed date field, 0 when the field carried none.

    ListFormat

    pub(all) enum ListFormat {
    Rfc3659
    UnixLs
    DosDir
    HostedFtp
    } derive(Eq,
    Debug
    )

    Which of the four parsers recognised a listing line. The order of the variants is the fallback order used by parse_list_line.

    ListFormat::equal

    fn ListFormat::equal(ListFormat, ListFormat) -> Bool

    ListFormat promotes its Eq and Debug methods as regular methods; declare the promotions explicitly so the deprecation warning stays away.

    ListFormat::not_equal

    fn ListFormat::not_equal(x : ListFormat, y : ListFormat) -> Bool

    ListFormat promotes its Eq and Debug methods as regular methods; declare the promotions explicitly so the deprecation warning stays away.

    Response

    pub struct Response {
    code : Int
    message : String
    } derive(
    Debug
    )

    A parsed FTP reply: the numeric status code and the (possibly multi line) message body.

    The body keeps the text of the framing status lines, matching the semantics of Go's textproto.ReadResponse; see read_response for why the callers depend on that.

    Response::code

    fn Response::code(self : Response) -> Int

    The status code of the reply.

    Response::message

    fn Response::message(self : Response) -> String

    The message body of the reply.

    Response::new

    fn Response::new(code : Int, message : String) -> Response

    Build a reply value.

    Response::to_repr

    Response promotes its Debug methods as regular methods; declare the promotion explicitly so the deprecation warning stays away.

    Scanner

    pub struct Scanner {
    src : String
    offset : Int
    }

    A whitespace separated field scanner, a faithful port of upstream scanner.go.

    The position semantics are not intuitive and upstream has a dedicated test for them, so they are spelled out here:

    new Scanner("foo bar x y") .next() -> "foo", position stops *after* the run of spaces .remaining() -> " bar x y" // the leading space is kept .next() -> "bar" .remaining() -> "x y"

    In other words next() consumes the field and exactly one following space. Everything after that stays in remaining().

    Scanner::at_end

    fn Scanner::at_end(self : Scanner) -> Bool

    Whether all input has been consumed.

    Scanner::new

    fn Scanner::new(src : String) -> Scanner

    Create a scanner over src.

    Scanner::next

    fn Scanner::next(self : Scanner) -> String

    Consume and return the next whitespace separated field.

    Returns "" at end of input. As in upstream, an empty field is only produced at the end — runs of spaces never yield empty fields.

    Scanner::next_fields

    fn Scanner::next_fields(self : Scanner, count : Int) -> Array[String]

    Read up to count consecutive fields. Stops early (without raising) when the input is exhausted, exactly like upstream nextFields.

    Scanner::remaining

    fn Scanner::remaining(self : Scanner) -> String

    The not-yet-consumed tail of the input.

    TransferType

    pub(all) enum TransferType {
    Binary
    ASCII
    } derive(Eq,
    Debug
    )

    The transfer type of the data connection, matching the FTP TYPE command arguments.

    TransferType::argument

    fn TransferType::argument(self : TransferType) -> String

    The FTP TYPE argument, an alias of to_string that reads better at the call site.

    TransferType::equal

    TransferType promotes its Eq and Debug methods as regular methods; declare the promotions explicitly so the deprecation warning stays away.

    TransferType::from_string

    fn TransferType::from_string(value : String) -> TransferType?

    Parse a TYPE command argument back into a TransferType, the inverse of TransferType::to_string.

    TransferType::not_equal

    fn TransferType::not_equal(x : TransferType, y : TransferType) -> Bool

    TransferType promotes its Eq and Debug methods as regular methods; declare the promotions explicitly so the deprecation warning stays away.

    TransferType::to_string

    fn TransferType::to_string(self : TransferType) -> String

    The argument string sent with the TYPE command.

    apply_list_time

    fn apply_list_time(entry : Entry, year : Int, month : Int, day : Int, has_time : Bool, hour : Int, minute : Int, now :
    ZonedDateTime
    ) -> Unit raise FtpError

    Interpret the MMM DD HH:MM / MMM DD YYYY time field of a LIST line.

    This is upstream's setTime including the six month rule from info ls 10.1.6:

    • when the field contains : there is no year, so the current year is assumed; if the resulting instant is not before now + 6 months, the year is decremented,
    • when the field has no : the year must be exactly four digits, a malformed year is an error (not a fallback),
    • a missing time (HH:MM) defaults to midnight.

    default_dial_timeout_ms

    let default_dial_timeout_ms : Int

    Default timeout used when dialing a server, in milliseconds (upstream ftp.DefaultDialTimeout, 30s).

    describe_error

    fn describe_error(err : Error) -> String

    A one-line human description of an FtpError, for diagnostics that go to stderr. Debug is for debugging -- it spells the package path, which makes a log line read PaiGack/ftp/core.FtpError.ServerError instead of the server answered 500.

    epoch

    The UNIX epoch, a convenient zero value for Entry::time.

    @time.ZonedDateTime::from_unix_second raises, which is awkward in pure parsers, so the fallback lives here where the failure path can be handled exactly once.

    find_date_start_pub

    fn find_date_start_pub(line : String, start : Int) -> Int?

    Index of the first MMM DD date field at or after start.

    flatten_errors

    fn flatten_errors(err : Error) -> Array[Error]

    Return every error carried by an aggregate, or the error itself when it is not an aggregate. Useful for tests and for re-raising partial failures.

    is_continuation

    fn is_continuation(line : String) -> Bool

    Whether the line is a multi line continuation (211-Features:), i.e. the fourth byte is -.

    is_positive_completion

    fn is_positive_completion(code : Int) -> Bool

    Whether the code is a 2xx "positive completion" reply.

    is_positive_intermediate

    fn is_positive_intermediate(code : Int) -> Bool

    Whether the code is a 1xx "positive intermediate" reply.

    join

    fn join(base : String, name : String) -> String

    Join two remote path fragments the way Go's path.Join does: the result is always cleaned (. dropped, .. resolved, no empty segment, no trailing slash), using / as separator. A leading / in the inputs is significant only for the first non-empty segment, matching path.Join.

    join("root/", "lo") == "root/lo" join("root", "a") == "root/a" join("root", "..") == "." join("", "a") == "a"

    join_all

    fn join_all(parts : Array[String]) -> String

    Variadic form of join, equivalent to path.Join(parts...).

    join_errors

    fn join_errors(errors : Array[Error]) -> Error?

    Build an aggregated error, collapsing the trivial cases so callers do not have to care about them:
    • no error at all -> None
    • exactly one error -> that error itself
    • otherwise -> FtpErrors::MultipleErrors

    make_entry

    fn make_entry(name : String, type_ : EntryType, time? :
    ZonedDateTime
    ) -> Entry

    Build an entry with the given name and type; the target defaults to the empty string and the time to the epoch in UTC, both of which the parsers overwrite when the server supplies the information.

    make_file

    fn make_file(name : String, time? :
    ZonedDateTime
    ) -> Entry

    Build a plain file entry, the most common shape.

    make_folder

    fn make_folder(name : String, time? :
    ZonedDateTime
    ) -> Entry

    Build a folder entry, the shape used by the walker root marker.
    fn make_link(name : String, target : String, time? :
    ZonedDateTime
    ) -> Entry

    Build a link entry with the given target.

    max_reply_line_bytes

    let max_reply_line_bytes : Int

    The longest single control-channel line read_response accepts, in bytes.

    RFC 959 caps a reply line at 512 bytes; the generous bound here is for the real world, not the RFC: FEAT descriptions, MLSD-style lines and PWD/257 paths with UTF8 names all run well past 512, and no legitimate server sends a megabyte on one line. What the bound exists for is the hostile case: read_until grows its buffer one read at a time with no upper limit, so a peer that never sends CRLF makes the client allocate without bound while the read stays "busy" and never trips the idle timeout.

    max_reply_lines

    let max_reply_lines : Int

    The most lines one multi-line reply may span before read_response gives up.

    A FEAT list or a long MLSD block is bounded by the number of features or files; nothing legitimate runs into the tens of thousands. A server that keeps answering continuation lines (or never repeats its code) would otherwise keep the while loop in read_response alive for as long as it keeps talking, which the idle timeout does not catch either.

    month_names

    let month_names : Array[String]

    The English month abbreviations accepted in LIST output, in calendar order (Jan == 1).

    new_datetime

    fn new_datetime(year : Int, month : Int, day : Int, hour : Int, minute : Int, zone :
    Zone
    ) ->
    ZonedDateTime
    raise FtpError

    Build a ZonedDateTime in zone, raising UnsupportedListDate when the calendar fields are not a valid date (e.g. Feb 30).

    parse_code

    fn parse_code(line : String) -> Int?

    Parse the leading three digits of a reply line.

    parse_dos_dir_line

    fn parse_dos_dir_line(line : String, now :
    ZonedDateTime
    ) -> Entry? raise FtpError

    Parse a MS-DOS / Windows DIR style line:

    07-27-17 04:50PM 1264086 File.txt 11-06-16 09:31AM <DIR> Softlib

    Faithful port of upstream parseDirListLine:

    • the first field is the date and is tried against four layouts (01-02-06 03:04PM with one or two digit month/day/year, and the 01-02-06 15:04 24 hour variant),
    • <DIR> switches the type to folder and the size to 0,
    • anything else must be a plain decimal size.

    parse_hostedftp_line

    fn parse_hostedftp_line(line : String, now :
    ZonedDateTime
    ) -> Entry? raise FtpError

    Parse a hostedftp.com style line, which is ls -l without the link count:

    drwxr-xr-x folder 0 Aug 15 05:49 !!!-Tipp des Haus!

    Upstream parseHostedFTPLine rewrites the first field by appending a space and the literal link count 0, then delegates to the Unix ls parser. Keeping that trick means the two parsers stay in sync.

    parse_list_date_field

    fn parse_list_date_field(src : String, start : Int) -> ListDateField?

    Parse the two year-dependent shapes used by the LIST time field, given the MMM DD prefix has already been consumed.

    Returns (year, month, day, has_time, hour, minute, next_index). year is 0 when the field carried no year at all (the HH:MM shape), the caller substitutes the current year.

    parse_list_line

    fn parse_list_line(line : String, now :
    ZonedDateTime
    ) -> (Entry, ListFormat) raise FtpError

    Parse a single LIST / MLSD line, trying the four parsers in the fixed fallback order documented in docs/porting.md section 1 (upstream analysis).

    line must not contain the trailing CR/LF. now is the reference instant used for the "no year" heuristic and is an explicit parameter so that the upstream test cases (fixed at 2017-03-10 23:00 UTC) stay reproducible.

    parse_ls_line

    fn parse_ls_line(line : String, now :
    ZonedDateTime
    ) -> Entry? raise FtpError

    Parse a Unix ls -l style line:

    drwxr-xr-x 3 110 1002 3 Dec 02 2009 pub -rw-r--r-- 1 marketwired marketwired 12016 Mar 16 2016 newsml drwxr-xr-x folder 0 Aug 15 05:49 !!!-Tipp des Haus!

    Port of upstream parseLsListLine:

    • the permission field is 10 bytes, or 11 with an ACL + marker,
    • the type comes from the first character,
    • the size is the last numeric field before the date, which is what makes the ls -l and the "no link count" variants both parse,
    • the date is found by scanning for MMM DD , so extra columns do not shift the parse,
    • the name is the entire remainder, so spaces inside names survive,
    • a symlink's -> is split into name and target.

    parse_ls_time

    fn parse_ls_time(src : String, start : Int, now :
    ZonedDateTime
    ) -> (
    ZonedDateTime
    , Int)? raise FtpError

    Parse an ls -l time field: MMM DD HH:MM or MMM DD YYYY.

    Returns the resolved time and the index right after the field.

    parse_month

    fn parse_month(name : String) -> Int?

    Parse a three letter month name case-insensitively, returning 1..12.

    parse_next_rfc3659_line

    fn parse_next_rfc3659_line(entry : Entry, line : String) -> Entry raise FtpError

    Merge the facts of a continuation line into the previous RFC 3659 entry. Some servers answer MLST with the same entry spread over several lines; upstream parseNextRFC3659ListLine requires the names to match.

    parse_rfc3659_line

    fn parse_rfc3659_line(line : String) -> Entry? raise FtpError

    Parse a single RFC 3659 (MLSD / MLST) fact line:

    type=file;size=951;modify=20140101000000; welcome.msg

    Faithful port of upstream parseRFC3659ListLine:

    • the facts are separated by ;, the last one is followed by the name,
    • fact keys are matched case-insensitively (Type= works as well, which is what WFTPD/Serv-U emit),
    • sizd is accepted as a typo for size,
    • an unrecognised type= value is an error, not a fallback,
    • a line whose last fact is not terminated by ; is not an RFC 3659 line.

    parse_uint

    fn parse_uint(digits : String, radix : Int) -> UInt64 raise FtpError

    Parse an unsigned 64 bit integer in the given radix, rejecting empty input and overflowing values.

    set_size

    fn set_size(raw : String) -> UInt64 raise FtpError

    Parse a numeric size field the way Go's strconv.ParseUint(s, 0, 64) does: an explicit 0x / 0X prefix means hex, 0o / 0O means octal, a leading 0 means octal, and anything else is decimal.

    status_action_not_taken

    let status_action_not_taken : Int

    The second spelling of 450. See the note in the file header: upstream calls this one StatusFileActionIgnored.

    status_auth_ok

    let status_auth_ok : Int

    status_bad_filename

    let status_bad_filename : Int

    status_cannot_open_data_connection

    let status_cannot_open_data_connection : Int

    status_closing_control_connection

    let status_closing_control_connection : Int

    221 Service closing control connection. — the answer to QUIT.

    status_closing_data_connection

    let status_closing_data_connection : Int

    status_cmd_not_implemented_superfluous

    let status_cmd_not_implemented_superfluous : Int

    status_cmd_ok

    let status_cmd_ok : Int

    status_data_conn_already_in_use

    let status_data_conn_already_in_use : Int

    status_data_connection_already_open

    let status_data_connection_already_open : Int

    status_data_connection_open_no_transfer

    let status_data_connection_open_no_transfer : Int

    status_dir_create

    let status_dir_create : Int

    status_dir_status

    let status_dir_status : Int

    status_enter_extended_passive_mode

    let status_enter_extended_passive_mode : Int

    status_enter_extended_port

    let status_enter_extended_port : Int

    status_enter_passive_mode

    let status_enter_passive_mode : Int

    status_enter_port

    let status_enter_port : Int

    status_entering_passive_mode_from_ip

    let status_entering_passive_mode_from_ip : Int

    status_exceeded_storage_allocation

    let status_exceeded_storage_allocation : Int

    status_file_action_aborted

    let status_file_action_aborted : Int

    status_file_action_aborted_local_error

    let status_file_action_aborted_local_error : Int

    status_file_action_not_taken

    let status_file_action_not_taken : Int

    status_file_action_ok

    let status_file_action_ok : Int

    status_file_action_pending_further_info

    let status_file_action_pending_further_info : Int

    status_file_status

    let status_file_status : Int

    status_help_message

    let status_help_message : Int

    status_name_status

    let status_name_status : Int

    status_need_account

    let status_need_account : Int

    status_need_account_for_login

    let status_need_account_for_login : Int

    status_not_implemented

    let status_not_implemented : Int

    status_not_implemented_for_param

    let status_not_implemented_for_param : Int

    status_not_logged_in

    let status_not_logged_in : Int

    status_page_type_unknown

    let status_page_type_unknown : Int

    status_request_denied

    let status_request_denied : Int

    status_restart_marker_answer

    let status_restart_marker_answer : Int

    RFC 959 / RFC 2228 / RFC 2428 / RFC 3659 status codes.

    The numeric values are kept identical to upstream status.go. Several distinct constants intentionally share the same numeric value (the RFCs overload the code), which is fine because they are plain Int constants. The names are this file's own spelling, not upstream's: upstream has one StatusFileActionIgnored for 450, where this file carries both status_file_action_not_taken and status_action_not_taken, because the two are read in different places and renaming either call site for a constant the client only compares by value would only hide which is which. Nothing here is matched by name across the module boundary, so a spelling difference cannot become a behaviour difference.

    status_restart_marker_not_understood

    let status_restart_marker_not_understood : Int

    status_restart_marker_reply

    let status_restart_marker_reply : Int

    status_service_ready_for_new_user

    let status_service_ready_for_new_user : Int

    status_service_ready_soon

    let status_service_ready_soon : Int

    status_service_unavailable

    let status_service_unavailable : Int

    status_session_opened_data_connection

    let status_session_opened_data_connection : Int

    status_syntax_error_unknown_cmd

    let status_syntax_error_unknown_cmd : Int

    status_syntax_error_unknown_params

    let status_syntax_error_unknown_params : Int

    status_system_status

    let status_system_status : Int

    status_text

    fn status_text(code : Int) -> String

    The human readable text for every known status code.

    The wording follows the RFC rather than upstream status.go: where upstream trimmed a sentence down (226 as "Closing data connection." versus its "Closing data connection. Requested file action successful."), the RFC wording is kept, so the text a user reads is the one the code means. No localization on purpose.

    status_transfer_aborted

    let status_transfer_aborted : Int

    status_user_logged_in_proceed

    let status_user_logged_in_proceed : Int

    status_username_ok

    let status_username_ok : Int

    status_username_ok_need_password

    let status_username_ok_need_password : Int

    warn_epsv_fallback

    fn warn_epsv_fallback(reason : String) -> Unit

    Say that a transfer fell back from EPSV to PASV because EPSV failed.

    The fallback is upstream behaviour and is kept -- some servers only speak one of the two -- but it is not free: the session latches PASV and keeps using it, and on an IPv6-only server PASV is usually refused, so one transient EPSV timeout can turn every later transfer into that refusal. Without a line on stderr the caller only sees the symptom.

    The failure is named, because "the server does not support EPSV" and "the EPSV reply was lost" call for different actions.

    warn_plaintext_login

    fn warn_plaintext_login(user : String) -> Unit

    Warn that a login was sent in the clear to a server that could have taken it over TLS.

    This is deliberately not an error. The password is already on the wire by the time anyone knows the server advertises AUTH TLS, and refusing the login would only break a session the caller may have chosen on purpose (a throwaway account on a lab network). What the library owes the caller is the fact: an operator reading the log can then decide, instead of finding out from a packet capture.

    user is named, the password never is -- this line is going into a log. The warning goes to stderr so that a CLI's stdout (a listing, a downloaded file's name) stays machine readable.