| 288 | } |
| 289 | |
| 290 | async fn insecure_connect(credentials: &FtpCredentials) -> Result<AsyncFtpStream, String> { |
| 291 | let result = |
| 292 | AsyncFtpStream::connect(format!("{}:{}", &credentials.host, &credentials.port)).await; |
| 293 | if result.is_err() { |
| 294 | return Err(format!( |
| 295 | "Unable to connect to FTP server at {}:{} (error: {})", |
| 296 | &credentials.host, |
| 297 | &credentials.port, |
| 298 | result.err().unwrap() |
| 299 | )); |
| 300 | } |
| 301 | |
| 302 | let mut ftp_stream = result.unwrap(); |
| 303 | |
| 304 | let result = ftp_stream |
| 305 | .login(&credentials.username, &credentials.password) |
| 306 | .await; |
| 307 | if result.is_err() { |
| 308 | return Err(format!( |
| 309 | "Invalid login credentials (error: {})", |
| 310 | result.err().unwrap() |
| 311 | )); |
| 312 | } |
| 313 | |
| 314 | let result = ftp_stream.cwd(&credentials.base_path).await; |
| 315 | if result.is_err() { |
| 316 | return Err(format!( |
| 317 | "Invalid base path: {} (error: {})", |
| 318 | &credentials.base_path, |
| 319 | result.err().unwrap() |
| 320 | )); |
| 321 | } |
| 322 | |
| 323 | // let result = ftp_stream.pwd().await; |
| 324 | // println!("PWD: {:?}", result); |
| 325 | |
| 326 | // Use passive mode |
| 327 | ftp_stream.set_mode(suppaftp::Mode::ExtendedPassive); |
| 328 | |
| 329 | Ok(ftp_stream) |
| 330 | } |
| 331 | |
| 332 | async fn secure_connect(credentials: &FtpCredentials) -> Result<AsyncNativeTlsFtpStream, String> { |
| 333 | let result = |