107 lines
3.1 KiB
Rust
107 lines
3.1 KiB
Rust
//! FTP request, response, and session models.
|
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
use crate::{
|
|
auth::AuthCredentialModel,
|
|
http::{HttpHeader, ProxyConfig, RetryStrategy, TlsConfig},
|
|
};
|
|
|
|
/// Transfer mode used by an FTP session.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub enum FtpMode {
|
|
/// Passive mode where the server accepts the data connection.
|
|
Passive,
|
|
/// Active mode where the client accepts the data connection.
|
|
Active,
|
|
}
|
|
|
|
/// Connection and retry settings for an FTP endpoint.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct FtpConfigModel {
|
|
/// Remote host name or IP.
|
|
pub host: String,
|
|
/// Remote control-port number.
|
|
pub port: u16,
|
|
/// Optional username for login.
|
|
pub username: Option<String>,
|
|
/// Optional password for login.
|
|
pub password: Option<String>,
|
|
/// Whether FTPS or other secure transport is expected.
|
|
pub secure: bool,
|
|
/// Active or passive data-channel mode.
|
|
pub mode: FtpMode,
|
|
/// Initial working directory after login.
|
|
pub initial_cwd: Option<String>,
|
|
/// Optional proxy configuration.
|
|
pub proxy: Option<ProxyConfig>,
|
|
/// Optional TLS tuning parameters.
|
|
pub tls: Option<TlsConfig>,
|
|
/// Retry strategy for failed requests.
|
|
pub retry: RetryStrategy,
|
|
}
|
|
|
|
/// FTP command issued within a request.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub enum FtpCommandModel {
|
|
/// `USER <name>`.
|
|
User(String),
|
|
/// `PASS <secret>`.
|
|
Pass(String),
|
|
/// `PWD`.
|
|
Pwd,
|
|
/// `CWD <path>`.
|
|
Cwd(String),
|
|
/// `LIST [path]`.
|
|
List(Option<String>),
|
|
/// `SIZE <path>`.
|
|
Size(String),
|
|
/// `REST <offset>`.
|
|
Rest(u64),
|
|
/// `RETR <path>`.
|
|
Retr(String),
|
|
/// `QUIT`.
|
|
Quit,
|
|
/// Caller-supplied custom FTP command text.
|
|
Custom(String),
|
|
}
|
|
|
|
/// FTP session state captured by the protocol layer.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct FtpSessionModel {
|
|
/// Stable session identifier.
|
|
pub session_id: String,
|
|
/// Resolved endpoint configuration.
|
|
pub config: FtpConfigModel,
|
|
/// Optional authenticated credential.
|
|
pub auth: Option<AuthCredentialModel>,
|
|
/// Default headers propagated into requests.
|
|
pub default_headers: Vec<HttpHeader>,
|
|
}
|
|
|
|
/// FTP request envelope passed into a connector.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct FtpRequestModel {
|
|
/// Command to execute.
|
|
pub command: FtpCommandModel,
|
|
/// Optional path or target associated with the command.
|
|
pub path: Option<String>,
|
|
/// Additional logical headers attached to the request.
|
|
pub headers: Vec<HttpHeader>,
|
|
}
|
|
|
|
/// FTP response material returned by a connector.
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
pub struct FtpResponseModel {
|
|
/// Numeric FTP status code.
|
|
pub code: u16,
|
|
/// Human-readable server message.
|
|
pub message: String,
|
|
/// Optional payload bytes such as directory listings or file contents.
|
|
pub data: Option<Vec<u8>>,
|
|
/// Optional path associated with the response.
|
|
pub path: Option<String>,
|
|
/// Whether the response can carry transferable data.
|
|
pub transferable: bool,
|
|
}
|