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

Function connect

bridge/src/client/data_store/sftp.rs:279–320  ·  view source on GitHub ↗
(credentials: &SftpCredentials)

Source from the content-addressed store, hash-verified

277}
278
279async fn connect(credentials: &SftpCredentials) -> Result<_Sftp, String> {
280 let result = SshSession::connect_mux(
281 format!(
282 "ssh://{}@{}:{}",
283 &credentials.username, &credentials.host, &credentials.port
284 ),
285 KnownHosts::Add,
286 )
287 .await;
288 if result.is_err() {
289 return Err(format!(
290 "Unable to connect to SSH server at {}:{} (error: {})",
291 &credentials.host,
292 &credentials.port,
293 result.err().unwrap()
294 ));
295 }
296
297 let ssh_session = result.unwrap();
298
299 let result = _Sftp::from_session(ssh_session, Default::default()).await;
300 if result.is_err() {
301 return Err(format!(
302 "Unable to establish to SFTP session from SSH session at {}:{} (error: {})",
303 &credentials.host,
304 &credentials.port,
305 result.err().unwrap()
306 ));
307 }
308
309 let sftp = result.unwrap();
310 let result = change_directory(&sftp, Some(&credentials.base_path)).await;
311 if result.is_err() {
312 return Err(format!(
313 "Invalid base path: {} (error: {})",
314 &credentials.base_path,
315 result.err().unwrap()
316 ));
317 }
318
319 Ok(sftp)
320}
321
322async fn disconnect(sftp: _Sftp) {
323 let result = sftp.close().await;

Callers 6

get_objectMethod · 0.85
upload_objectMethod · 0.85
list_objectsMethod · 0.85
test_connectionFunction · 0.85
insecure_connectFunction · 0.85
secure_connectFunction · 0.85

Calls 1

change_directoryFunction · 0.70

Tested by 1

test_connectionFunction · 0.68