MCPcopy Create free account
hub / github.com/BitVM/BitVM / secure_connect

Function secure_connect

bridge/src/client/data_store/ftp/lib.rs:332–387  ·  view source on GitHub ↗
(credentials: &FtpCredentials)

Source from the content-addressed store, hash-verified

330}
331
332async fn secure_connect(credentials: &FtpCredentials) -> Result<AsyncNativeTlsFtpStream, String> {
333 let result =
334 AsyncNativeTlsFtpStream::connect(format!("{}:{}", &credentials.host, &credentials.port))
335 .await;
336 if result.is_err() {
337 return Err(format!(
338 "Unable to connect to FTPS server at {}:{} (error: {})",
339 &credentials.host,
340 &credentials.port,
341 result.err().unwrap()
342 ));
343 }
344
345 let result = result
346 .unwrap()
347 .into_secure(
348 AsyncNativeTlsConnector::from(TlsConnector::new()),
349 &credentials.host,
350 )
351 .await;
352 if result.is_err() {
353 return Err(format!(
354 "Unable to switch to secure ssl (error: {})",
355 result.err().unwrap()
356 ));
357 }
358
359 let mut ftp_stream = result.unwrap();
360
361 let result = ftp_stream
362 .login(&credentials.username, &credentials.password)
363 .await;
364 if result.is_err() {
365 return Err(format!(
366 "Invalid login credentials (error: {})",
367 result.err().unwrap()
368 ));
369 }
370
371 let result = ftp_stream.cwd(&credentials.base_path).await;
372 if result.is_err() {
373 return Err(format!(
374 "Invalid base path: {} (error: {})",
375 &credentials.base_path,
376 result.err().unwrap()
377 ));
378 }
379
380 // let result = ftp_stream.pwd().await;
381 // println!("PWD: {:?}", result);
382
383 // Use passive mode
384 ftp_stream.set_mode(suppaftp::Mode::Passive);
385
386 Ok(ftp_stream)
387}
388
389async fn disconnect(

Callers 4

test_connectionFunction · 0.85
list_objectsFunction · 0.85
get_objectFunction · 0.85
upload_fileFunction · 0.85

Calls 1

connectFunction · 0.85

Tested by 1

test_connectionFunction · 0.68