This project implements a robust, extensible command-line FTP client in Java, capable of performing a wide range of FTP operations including listing directories, copying files, moving files, and creating/deleting directories on remote FTP servers.
I designed this FTP client using a variant of the command pattern, emphasizing modularity and ease of extension:
Main
: Serves as the entry point, handling command-line argument parsing and orchestrating FTP command execution.FTPClient
: Implements core FTP functionality, managing server connections and executing FTP commands.FTPCommand
andFTPExecutor
: Establishes the foundation for my command pattern implementation. The Executor manages the entire connection lifecycle centrally.FTPPathHandler
: Specializes in parsing and handling FTP URLs and local paths.ParseArgs
: Efficiently parses and structures command-line arguments.
My approach to the command pattern allows for easy maintenance and extensibility:
- FTP operations are encapsulated as methods within the
FTPClient
class. - A
BiFunction
HashMap in theMain
class maps command strings to their corresponding operations. - To add a new command, one only needs to:
- Implement the operation in the
FTPClient
class. - Add a single entry to the
BiFunction
HashMap inMain
.
- Implement the operation in the
This streamlined process automatically handles connections and error management for any new command, significantly reducing the complexity of extending the client's functionality.
One of my most significant challenges was developing an efficient testing methodology for the FTP client. My solution is an innovative record-replay approach, implemented in the FTPCommandTest
class.
-
Recording Mode:
- Connects to an actual FTP server and executes a comprehensive series of FTP commands.
- Responses are recorded and serialized to
ftp_test_cases.dat
.
-
Replay Mode:
- Deserializes previously recorded responses.
- Executes tests by comparing recorded responses against expected results.
-
FTPRecorder Class:
- Manages the recording and replaying of test cases.
- Provides persistent storage of test data.
This approach offers two advantages:
- Consistent test environment without relying on a live FTP server.
- Comprehensive coverage of various scenarios, including error cases.
- Developing a mock FTP server that can simulate various server behaviors using the recorded interaction data.
- Investigating the integration of existing Java libraries to improve my record-replay mechanism.
- Implementing a hybrid approach that combines my record-replay tests with live integration tests for more robust coverage.