use crate::{
models::{CreateFtp, FtpAccount, ModifyFtp},
CpanelClient, CpanelError,
};
impl CpanelClient {
pub async fn list_ftp_accounts(&self, user: &str) -> Result<Vec<FtpAccount>, CpanelError> {
let result: Vec<FtpAccount> = self
.uapi("Ftp", "list_ftp_accounts", &[("user", user)])
.await?;
Ok(result)
}
pub async fn create_ftp_account(
&self,
user: &str,
create: &CreateFtp,
) -> Result<(), CpanelError> {
let mut params: Vec<(&str, String)> = vec![
("user", user.to_string()),
("login", create.username.clone()),
("password", create.password.clone()),
];
if let Some(ref s) = create.path {
params.push(("path", s.clone()));
}
if let Some(q) = create.quota {
params.push(("quota", q.to_string()));
}
let params: Vec<(&str, &str)> = params.iter().map(|(k, v)| (*k, v.as_str())).collect();
let _: () = self.uapi("Ftp", "add_ftp", ¶ms).await?;
Ok(())
}
pub async fn modify_ftp_account(
&self,
user: &str,
modify: &ModifyFtp,
) -> Result<(), CpanelError> {
let mut params: Vec<(&str, String)> = vec![
("user", user.to_string()),
("login", modify.username.clone()),
];
if let Some(ref s) = modify.password {
params.push(("password", s.clone()));
}
if let Some(ref s) = modify.path {
params.push(("path", s.clone()));
}
if let Some(q) = modify.quota {
params.push(("quota", q.to_string()));
}
let params: Vec<(&str, &str)> = params.iter().map(|(k, v)| (*k, v.as_str())).collect();
let _: () = self.uapi("Ftp", "edit_ftp", ¶ms).await?;
Ok(())
}
pub async fn delete_ftp_account(&self, user: &str, username: &str) -> Result<(), CpanelError> {
let _: () = self
.uapi("Ftp", "del_ftp", &[("user", user), ("login", username)])
.await?;
Ok(())
}
}