SatCat5
file_tftp.h
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // TFTP client and server implementation using FileReader and FileWriter
6 
7 #pragma once
8 
9 #include <hal_posix/file_io.h>
10 #include <satcat5/udp_tftp.h>
11 #include <string>
12 
13 namespace satcat5 {
14  namespace udp {
18  {
19  public:
21  explicit TftpClientPosix(satcat5::udp::Dispatch* iface);
22  virtual ~TftpClientPosix();
23 
25  void begin_download(
26  const satcat5::ip::Addr& server,
27  const char* filename_local,
28  const char* filename_remote);
29 
31  void begin_upload(
32  const satcat5::ip::Addr& server,
33  const char* filename_local,
34  const char* filename_remote);
35 
38  inline bool active() const
39  {return m_tftp.active();}
40  inline u32 progress_blocks() const
41  {return m_tftp.progress_blocks();}
42  inline u32 progress_bytes() const
43  {return m_tftp.progress_bytes();}
45 
46  protected:
47  // Interface objects.
51  };
52 
58  public:
62  const char* work_folder);
63  virtual ~TftpServerPosix();
64 
65  protected:
67  std::string check_path(const char* filename);
68 
69  // Required overrides from TftpServer.
70  satcat5::io::Readable* read(const char* filename) override;
71  satcat5::io::Writeable* write(const char* filename) override;
72 
73  // Interface objects.
74  const std::string m_work_folder;
77  };
78  }
79 }
Read bytes or packets from a file.
Definition: file_io.h:48
Write bytes or packets to a file.
Definition: file_io.h:16
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Abstract API for writing byte-streams and packets.
Definition: io_writeable.h:24
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
A TFTP client makes request(s) to a remote server.
Definition: udp_tftp.h:111
u32 progress_bytes() const
Transfer progress, measured in bytes.
Definition: udp_tftp.h:136
u32 progress_blocks() const
Transfer progress, measured in 512-byte blocks.
Definition: udp_tftp.h:133
bool active() const
Is there an active transfer?
Definition: udp_tftp.h:130
A TFTP client that makes request(s) to a remote server.
Definition: file_tftp.h:18
u32 progress_blocks() const
Accessors for the transfer status.
Definition: file_tftp.h:40
u32 progress_bytes() const
Accessors for the transfer status.
Definition: file_tftp.h:42
void begin_upload(const satcat5::ip::Addr &server, const char *filename_local, const char *filename_remote)
Upload data from a Readable stream to the server.
Definition: file_tftp.cc:44
void begin_download(const satcat5::ip::Addr &server, const char *filename_local, const char *filename_remote)
Download a file from server to a Writeable stream.
Definition: file_tftp.cc:35
TftpClientPosix(satcat5::udp::Dispatch *iface)
Attach this TFTP client to a network interface.
Definition: file_tftp.cc:21
bool active() const
Accessors for the transfer status.
Definition: file_tftp.h:38
ServerCore is the base class that handles TFTP network functions.
Definition: udp_tftp.h:150
A TFTP server handles requests from remote clients.
Definition: file_tftp.h:57
std::string check_path(const char *filename)
Check if a user-supplied path is safe to use.
Definition: file_tftp.cc:73
satcat5::io::Readable * read(const char *filename) override
Child class MUST override these methods.
Definition: file_tftp.cc:83
TftpServerPosix(satcat5::udp::Dispatch *iface, const char *work_folder)
Attach this TFTP server to a network interface.
Definition: file_tftp.cc:56
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15
Client and server for the Trivial File Transfer Protocol (TFTP)