TFTP(3pm)

πŸ“¦
version 0.1901 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Net::TFTP β€” the TFTP Client class, bestie edition πŸ’–

okay so welcome to Net::TFTP, a whole Perl module living in the TFTP(3pm) slot of your manual, from the User Contributed Perl Documentation corner of the world. it's the TFTP client class. yes THE one. we're doing file transfers and we're doing them cute. πŸŽ€


✨ NAME ✨

Net::TFTP β€” TFTP Client class, she's a whole vibe πŸ’…


🌸 SYNOPSIS 🌸

like, here's the entire flex in one go, no cap:

use Net::TFTP;

$tftp = Net::TFTP->new("some.host.name", BlockSize => 1024);

$tftp->ascii;

$tftp->get("remotefile", "localfile");

$tftp->get("remotefile", \*STDOUT);

$fh = $tftp->get("remotefile");

$tftp->binary;

$tftp->put("localfile", "remotefile");

$tftp->put(\*STDOUT, "remotefile");

$fh = $tftp->put("remotefile");

$err = $tftp->error

look at her. iconic behavior fr fr. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so Net::TFTP is a class implementing a simple Trivial File Transfer Protocol client in Perl, exactly as described in RFC1350. periodt.

and because she's generous, Net::TFTP also supports the TFTP Option Extension (as described in RFC2347), with the following options:

that's it, that's the list, that's the whole glow-up.


πŸŽ€ CONSTRUCTOR πŸŽ€

new ( [ HOST ] [, OPTIONS ])

okay so this creates a new Net::TFTP object, bestie. here's the deal:

  • HOST = the default host to connect to
  • OPTIONS = the default transfer options

and the valid options are giving:

  • Timeout β€” Timeout in seconds before retry β€” default: 5
  • Retries β€” Maximum number of retries β€” default: 5
  • Port β€” Port to send data to β€” default: 69
  • Mode β€” Mode to transfer data in, "octet" or "netascii" β€” default: "netascii"
  • BlockSize β€” Negotiate size of blocks to use in the transfer β€” default: 512
  • IpMode β€” Indicates whether to operate in IPv6 mode β€” default: "v4"

memorize these. they're your defaults. they're the blueprint. πŸ’–


🌈 METHODS 🌈

get ( REMOTE_FILE [, LOCAL ] [, OPTIONS ])

get REMOTE_FILE from the server, slay. πŸ’…

the OPTIONS can be any that are accepted by new, plus the following:

  • Host β€” Override default host

now listen, this part matters:

if the LOCAL option is missing, the get will return a filehandle. and this filehandle must be read ASAP because the server will otherwise timeout. like, do not ghost it. it will leave you on read and you will lose data. 😭

if the LOCAL option is given, then it can be a file name or a reference. if it is a reference, it is assumed to be a reference that is valid as a filehandle. get will return true if the transfer is successful and undef otherwise.

valid filehandles are:

  • A sub-class of IO::Handle
  • A tied filehandle
  • A GLOB reference (eg "\*STDOUT")

those are the three. the holy trinity. 🫢


put ( [ LOCAL, ] REMOTE_FILE [, OPTIONS])

put a file to the server as REMOTE_FILE, we're uploading bestie, no big deal. ✨

the OPTIONS can be any that are accepted by new, plus the following:

  • Host β€” Override default host

if the LOCAL option is missing, the put will return a filehandle. and this filehandle must be written to ASAP because the server will otherwise timeout. same energy as get β€” do not delay, do not pass go.

if the LOCAL option is given, then it can be a file name or a reference. if it is a reference, it is assumed to be a valid filehandle as described above. put will return true if the transfer is successful and undef otherwise.


error

if there was an error, then this method will return an error string. that's it. she tells you what went wrong. πŸ’€


host ( [ HOST ] )

timeout ( [ TIMEOUT ] )

port ( [ PORT ] )

mode ( [ MODE ] )

retries ( [ VALUE ] )

block_size ( [ VALUE ] )

debug ( [ VALUE ] )

set or get the values for the various options. here's how it works:

  • if an argument is passed, then a new value is set for that option and the previous value is returned
  • if no value is passed, then the current value is returned

so she's a getter AND a setter. dual threat. main character energy, honestly. πŸ‘‘


ip_mode ( [ VALUE ] )

set or get which verion of IP to use ("v4" or "v6").

ok yes the original says "verion" and I am NOT fixing it, that's the canon, we preserve the canon, no cap. 🫢

ascii

netascii

set the transfer mode to "netascii".


binary

octet

set the transfer mode to "octet".


πŸ’œ AUTHOR πŸ’œ

Graham Barr <gbarr@pobox.com> β€” shoutout to the actual legend who wrote this. πŸ‘‘


Copyright (c) 1998,2007 Graham Barr. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay bestie that's the whole page, you're officially fluent in Net::TFTP, go transfer some files responsibly. πŸ¦‹βœ¨

and a lil sign-off just for you: this page came from perl v5.36.0, dated 2022-10-13, and it lives under TFTP(3pm). stay iconic, read your RFCs, hydrate. πŸ’–πŸŽ€πŸŒˆ

πŸ“¦ where this page comes from