Skip to content

Commit

Permalink
Done:
Browse files Browse the repository at this point in the history
"Cargo.toml":
Hide FTP support under new feature flag.

"operator.rs", "scheme.rs, src/services/mod.rs":
Added conditional compilation for ftp services.

"src/services/ftp/backend.rs":
Removed any unnecessary helper functions that only use
once.
Removed username and password store to avoid data breach.
Combine port and endpoint into one.
Built a FTP command stream inside Builder's build() function
and persist this stream inside Backend.
Changed tls to enable_secure. Developer can use enable_secure() function
to enable tls connection.
Modified read() function to avoid putting all stream content into memory.
Fixed stat() function, when path argument is empty, stat() function will
return the stat of root directory.

"src/services/ftp/dir_stream.rs"
Added more metadata in DirEntry.

"src/services/ftp/err.rs":
Removed any unnecessary error functions.

"src/services/ftp/mod.rs":
Remove empty line.

"tests/behavior/behavior.rs":
Added feature for ftp.

Resolve conflict.
  • Loading branch information
ArberSephirotheca committed Sep 2, 2022
1 parent 1f69945 commit ed99646
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 348 deletions.
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ OPENDAL_FTP_TEST=false
OPENDAL_FTP_ENDPOINT=<endpoint>
OPENDAL_FTP_ROOT=/path/to/dir
OPENDAL_FTP_USER=<user>
OPENDAL_FTP_PASSWORD=<password>


OPENDAL_FTP_PASSWORD=<password>
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ layers-tracing = ["tracing"]
services-hdfs = ["hdrs"]
# Enable services http support
services-http = ["radix_trie"]
# Enable services ftp support
services-ftp = ["suppaftp"]

[lib]
bench = false
Expand Down Expand Up @@ -89,7 +91,7 @@ thiserror = "1.0"
time = "0.3"
tokio = { version = "1.20", features = ["fs"] }
tracing = { version = "0.1", optional = true }
suppaftp = {version = "^4.4.0", features = ["secure"]}
suppaftp = {version = "4.4", features = ["secure"], optional = true}

[dev-dependencies]
cfg-if = "1.0"
Expand Down
17 changes: 7 additions & 10 deletions examples/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ async fn main() -> Result<()> {
Available Environment Values:
- OPENDAL_FTP_ENDPOINT=endpoint # required
- OPENDAL_FTP_Port=port # default with 21
- OPENDAL_FTP_ROOT=/path/to/dir/ # if not set, will be seen as "/ftp"
- OPENDAL_FTP_ROOT=/path/to/dir/ # if not set, will be seen as "/"
- OPENDAL_FTP_USER=user # default with empty string ""
- OPENDAL_FTP_PWD=password # default with empty string ""
- OPENDAL_FTP_TLS=bool # default with false
- OPENDAL_FTP_PASSWORD=password # default with empty string ""
"#
);

Expand All @@ -47,11 +45,10 @@ Available Environment Values:
// Set the root for ftp, all operations will happen under this root.

// NOTE: the root must be absolute path.
builder.endpoint(&env::var("OPENDAL_FTP_ENDPOINT").unwrap_or_else(|_| "127.0.0.1".to_string()));
builder
.endpoint(&env::var("OPENDAL_FTP_ENDPOINT").unwrap_or_else(|_| "127.0.0.1:21".to_string()));
builder.user(&env::var("OPENDAL_FTP_USER").unwrap_or_else(|_| "".to_string()));
builder.password(&env::var("OPENDAL_FTP_PWD").unwrap_or_else(|_| "".to_string()));
builder.port(&env::var("OPENDAL_FTP_PORT").unwrap_or_else(|_| "21".to_string()));
builder.tls(&env::var("OPENDAL_FTP_TLS").unwrap_or_else(|_| "false".to_string()));
builder.password(&env::var("OPENDAL_FTP_PASSWORD").unwrap_or_else(|_| "".to_string()));

// Use `Operator` normally.
let op: Operator = Operator::new(builder.build()?);
Expand All @@ -78,8 +75,8 @@ Available Environment Values:
op.object(&path).write("write test").await?;
info!("write to file successful!",);

info!("try to read file: {}", &path);
let content = op.object(&path).read().await?;
info!("try to read file content between 5-10: {}", &path);
let content = op.object(&path).range_read(5..10).await?;
info!(
"read file successful, content: {}",
String::from_utf8_lossy(&content)
Expand Down
2 changes: 1 addition & 1 deletion src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ impl Operator {
Scheme::Hdfs => services::hdfs::Backend::from_iter(it)?.into(),
#[cfg(feature = "services-http")]
Scheme::Http => services::http::Backend::from_iter(it)?.into(),
Scheme::Ipfs => services::ipfs::Backend::from_iter(it)?.into(),
#[cfg(feature = "services-ftp")]
Scheme::Ftp => services::ftp::Backend::from_iter(it)?.into(),
Scheme::Ipfs => services::ipfs::Backend::from_iter(it)?.into(),
Scheme::Memory => services::memory::Builder::default().build()?.into(),
Scheme::Gcs => services::gcs::Backend::from_iter(it)?.into(),
Scheme::S3 => services::s3::Backend::from_iter(it)?.into(),
Expand Down
1 change: 1 addition & 0 deletions src/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl FromStr for Scheme {
#[cfg(feature = "services-ftp")]
"ftp" => Ok(Scheme::Ftp),
"ipfs" => Ok(Scheme::Ipfs),
"gcs" => Ok(Scheme::Gcs),
"memory" => Ok(Scheme::Memory),
"obs" => Ok(Scheme::Obs),
"s3" => Ok(Scheme::S3),
Expand Down
Loading

0 comments on commit ed99646

Please sign in to comment.