Skip to content

Commit

Permalink
feat: SITE command
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed May 18, 2024
1 parent cbd530d commit 55f4dc1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

Released on 18/05/2024

- [Issue 70](https://github.com/veeso/suppaftp/issues/70): **SITE** Command
- [Issue 75](https://github.com/veeso/suppaftp/issues/75): Public access to `connect_with_stream`
- [PR 78](https://github.com/veeso/suppaftp/pull/78): Async SSL file uploads not properly closing
- `custom_command`: added `custom_command` function to perform custom commands
Expand Down
7 changes: 7 additions & 0 deletions suppaftp/src/async_ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,13 @@ where
Ok(())
}

/// Execute a command on the server and return the response
pub async fn site(&mut self, command: impl ToString) -> FtpResult<()> {
debug!("Sending SITE command: {}", command.to_string());
self.perform(Command::Site(command.to_string())).await?;
self.read_response(Status::CommandOk).await.map(|_| ())
}

/// Perform custom command
pub async fn custom_command(
&mut self,
Expand Down
9 changes: 9 additions & 0 deletions suppaftp/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub enum Command {
Retr(String),
/// Remove directory
Rmd(String),
/// Site command
Site(String),
/// Get file size of specified path
Size(String),
/// Put file at specified path
Expand Down Expand Up @@ -156,6 +158,7 @@ impl fmt::Display for Command {
Self::Rest(offset) => format!("REST {offset}"),
Self::Retr(p) => format!("RETR {p}"),
Self::Rmd(p) => format!("RMD {p}"),
Self::Site(p) => format!("SITE {p}"),
Self::Size(p) => format!("SIZE {p}"),
Self::Store(p) => format!("STOR {p}"),
Self::Type(t) => format!("TYPE {t}"),
Expand Down Expand Up @@ -309,6 +312,12 @@ mod test {
Command::Rmd(String::from("/tmp")).to_string().as_str(),
"RMD /tmp\r\n"
);
assert_eq!(
Command::Site(String::from("chmod 755 a.txt"))
.to_string()
.as_str(),
"SITE chmopd 755 a.txt\r\n"
);
assert_eq!(
Command::Size(String::from("a.txt")).to_string().as_str(),
"SIZE a.txt\r\n"
Expand Down
7 changes: 7 additions & 0 deletions suppaftp/src/sync_ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,13 @@ where
Ok(())
}

/// Execute a command on the server and return the response
pub fn site(&mut self, command: impl ToString) -> FtpResult<()> {
debug!("Sending SITE command: {}", command.to_string());
self.perform(Command::Site(command.to_string()))?;
self.read_response(Status::CommandOk).map(|_| ())
}

/// Perform custom command
pub fn custom_command(
&mut self,
Expand Down

0 comments on commit 55f4dc1

Please sign in to comment.