ssh-mcp-rs 2.1.0

MCP server exposing SSH control for Linux systems via Model Context Protocol
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
//! Transport fallback chain tests
//! Tests that the system correctly falls back through the transport chain:
//! rsync -> sftp -> scp -> execraw
#![cfg(unix)]

use super::common::*;
use std::path::PathBuf;
use std::time::SystemTime;

/// Test fallback from rsync to sftp when rsync is not available on remote.
/// The ssh-mcp-debian-sshd container does not include rsync by default,
/// so using Auto transport should fall back from rsync to sftp.
#[tokio::test]
async fn test_fallback_from_rsync_to_sftp() {
    init_test_env().expect("Failed to initialize test environment");

    let _ = tracing_subscriber::fmt()
        .with_test_writer()
        .with_env_filter("ssh_mcp=debug,info")
        .try_init();

    // Skip if local rsync is not available (can't test fallback from unavailable tool)
    if !check_rsync() {
        tracing::warn!("skipping: local 'rsync' unavailable");
        return;
    }

    // Skip if local sftp is not available (can't verify fallback target)
    if !check_sftp() {
        tracing::warn!("skipping: local 'sftp' unavailable");
        return;
    }

    let (_key_dir, key_path) = setup_test_key();

    // Start SSH container (Debian-based, no rsync installed)
    let container = GenericImage::new("ssh-mcp-debian-sshd-norsync", "latest")
        .with_exposed_port(2222u16.into())
        .start()
        .await
        .expect("Failed to start SSH container");

    let host = container
        .get_host()
        .await
        .expect("Failed to get container host");
    let port = container
        .get_host_port_ipv4(2222)
        .await
        .expect("Failed to get mapped SSH port");
    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;

    let config = Config {
        host: host.to_string(),
        port,
        user: "test".to_string(),
        password: None,
        key: Some(key_path),
        su_password: None,
        sudo_password: None,
        timeout_ms: 30000,
        max_chars: Some(1000),
        max_output_tokens: Some(12000),
        disable_sudo: true,
        keepalive_interval: 30,
        keepalive_max: 3,
        reconnect_retries: 3,
        reconnect_backoff_ms: 250,
        health_probe_timeout_ms: 1500,
        strict_host_key_checking: ssh_mcp::HostKeyCheckMode::No,
        known_hosts: None,
    };

    let server = SshMcpServer::new(config)
        .await
        .expect("Failed to create SshMcpServer");

    // Resolve remote home
    let home_result = server
        .test_execute_command(r#"sh -c 'printf %s "$HOME"'"#)
        .await
        .expect("failed to resolve remote HOME");
    let remote_home = extract_text_from_result(&home_result).trim().to_string();

    // Create local file
    let unique = format!(
        "{}-{}-fallback-rsync-sftp",
        std::process::id(),
        SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .map(|d| d.as_nanos())
            .unwrap_or(0)
    );
    let local_base = PathBuf::from("target/tmp").join(format!("fallback-rsync-sftp-{unique}"));
    std::fs::create_dir_all(&local_base).expect("create local base");

    let local_file = local_base.join("hello.txt");
    std::fs::write(&local_file, "hello via fallback to sftp\n").expect("write local file");

    let local_path_param = local_file.to_string_lossy().to_string();
    let remote_file = format!("{}/fallback-rsync-sftp.txt", remote_home);

    // Use Auto transport - should try rsync first, then fall back to sftp
    let resp = server
        .test_transfer(TransferParams {
            operation: TransferOperation::Put,
            local_path: local_path_param,
            remote_path: remote_file.clone(),
            transport: TransferTransport::Auto,
            kind: Some(TransferKind::File),
            overwrite: true,
            timeout_ms: Some(30000),
            verbose: false,
            ..Default::default()
        })
        .await;

    assert!(
        resp.ok,
        "transfer with Auto transport should succeed: {:?}",
        resp.error
    );
    assert_eq!(
        resp.transport_used,
        TransferTransport::Sftp,
        "should fallback from rsync to sftp when rsync unavailable on remote"
    );

    // Verify content on remote
    let verify = server
        .test_execute_command(&format!(
            "sh -c 'cat < {}'",
            ssh_mcp::escape_for_shell(&remote_file)
        ))
        .await
        .expect("verify remote file");
    let verify_text = extract_text_from_result(&verify);
    assert!(
        verify_text.contains("hello via fallback to sftp"),
        "remote file should contain expected content after fallback"
    );

    server.shutdown().await;
    let _ = std::fs::remove_dir_all(&local_base);
}

/// Test fallback from rsync to scp when rsync is unavailable.
/// This tests the scenario where sftp might also be unavailable or fails,
/// causing the system to fall back to scp.
#[tokio::test]
async fn test_fallback_from_rsync_to_scp() {
    init_test_env().expect("Failed to initialize test environment");

    let _ = tracing_subscriber::fmt()
        .with_test_writer()
        .with_env_filter("ssh_mcp=debug,info")
        .try_init();

    // Skip if local rsync is not available
    if !check_rsync() {
        tracing::warn!("skipping: local 'rsync' unavailable");
        return;
    }

    // Skip if local scp is not available (can't verify fallback target)
    if !check_scp() {
        tracing::warn!("skipping: local 'scp' unavailable");
        return;
    }

    let (_key_dir, key_path) = setup_test_key();

    // Start SSH container (Debian-based, no rsync installed)
    let container = GenericImage::new("ssh-mcp-debian-sshd-norsync", "latest")
        .with_exposed_port(2222u16.into())
        .start()
        .await
        .expect("Failed to start SSH container");

    let host = container
        .get_host()
        .await
        .expect("Failed to get container host");
    let port = container
        .get_host_port_ipv4(2222)
        .await
        .expect("Failed to get mapped SSH port");
    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;

    let config = Config {
        host: host.to_string(),
        port,
        user: "test".to_string(),
        password: None,
        key: Some(key_path),
        su_password: None,
        sudo_password: None,
        timeout_ms: 30000,
        max_chars: Some(1000),
        max_output_tokens: Some(12000),
        disable_sudo: true,
        keepalive_interval: 30,
        keepalive_max: 3,
        reconnect_retries: 3,
        reconnect_backoff_ms: 250,
        health_probe_timeout_ms: 1500,
        strict_host_key_checking: ssh_mcp::HostKeyCheckMode::No,
        known_hosts: None,
    };

    let server = SshMcpServer::new(config)
        .await
        .expect("Failed to create SshMcpServer");

    // Resolve remote home
    let home_result = server
        .test_execute_command(r#"sh -c 'printf %s "$HOME"'"#)
        .await
        .expect("failed to resolve remote HOME");
    let remote_home = extract_text_from_result(&home_result).trim().to_string();

    // Create local file
    let unique = format!(
        "{}-{}-fallback-rsync-scp",
        std::process::id(),
        SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .map(|d| d.as_nanos())
            .unwrap_or(0)
    );
    let local_base = PathBuf::from("target/tmp").join(format!("fallback-rsync-scp-{unique}"));
    std::fs::create_dir_all(&local_base).expect("create local base");

    let local_file = local_base.join("hello.txt");
    std::fs::write(&local_file, "hello via fallback to scp\n").expect("write local file");

    let local_path_param = local_file.to_string_lossy().to_string();
    let remote_file = format!("{}/fallback-rsync-scp.txt", remote_home);

    // Use Auto transport with a forced scp fallback by using Scp transport directly
    // to simulate the scenario where rsync is unavailable and sftp fails.
    // Since we can't easily disable sftp (it's built into sshd), we document that
    // this test verifies the scp transport works as a valid fallback option.
    let resp = server
        .test_transfer(TransferParams {
            operation: TransferOperation::Put,
            local_path: local_path_param,
            remote_path: remote_file.clone(),
            transport: TransferTransport::Scp,
            kind: Some(TransferKind::File),
            overwrite: true,
            timeout_ms: Some(30000),
            verbose: false,
            ..Default::default()
        })
        .await;

    assert!(
        resp.ok,
        "transfer with Scp transport should succeed: {:?}",
        resp.error
    );
    assert_eq!(
        resp.transport_used,
        TransferTransport::Scp,
        "should use scp as fallback transport"
    );

    // Verify content on remote
    let verify = server
        .test_execute_command(&format!(
            "sh -c 'cat < {}'",
            ssh_mcp::escape_for_shell(&remote_file)
        ))
        .await
        .expect("verify remote file");
    let verify_text = extract_text_from_result(&verify);
    assert!(
        verify_text.contains("hello via fallback to scp"),
        "remote file should contain expected content after scp transfer"
    );

    server.shutdown().await;
    let _ = std::fs::remove_dir_all(&local_base);
}

/// Test fallback from sftp to scp when sftp is unavailable.
/// This verifies that the system can fall back to scp when sftp subsystem fails.
#[tokio::test]
async fn test_fallback_from_sftp_to_scp() {
    init_test_env().expect("Failed to initialize test environment");

    let _ = tracing_subscriber::fmt()
        .with_test_writer()
        .with_env_filter("ssh_mcp=debug,info")
        .try_init();

    // Skip if local sftp is not available
    if !check_sftp() {
        tracing::warn!("skipping: local 'sftp' unavailable");
        return;
    }

    // Skip if local scp is not available
    if !check_scp() {
        tracing::warn!("skipping: local 'scp' unavailable");
        return;
    }

    let (_key_dir, key_path) = setup_test_key();

    // Start SSH container
    let container = GenericImage::new("ssh-mcp-debian-sshd", "latest")
        .with_exposed_port(2222u16.into())
        .start()
        .await
        .expect("Failed to start SSH container");

    let host = container
        .get_host()
        .await
        .expect("Failed to get container host");
    let port = container
        .get_host_port_ipv4(2222)
        .await
        .expect("Failed to get mapped SSH port");
    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;

    let config = Config {
        host: host.to_string(),
        port,
        user: "test".to_string(),
        password: None,
        key: Some(key_path),
        su_password: None,
        sudo_password: None,
        timeout_ms: 30000,
        max_chars: Some(1000),
        max_output_tokens: Some(12000),
        disable_sudo: true,
        keepalive_interval: 30,
        keepalive_max: 3,
        reconnect_retries: 3,
        reconnect_backoff_ms: 250,
        health_probe_timeout_ms: 1500,
        strict_host_key_checking: ssh_mcp::HostKeyCheckMode::No,
        known_hosts: None,
    };

    let server = SshMcpServer::new(config)
        .await
        .expect("Failed to create SshMcpServer");

    // Resolve remote home
    let home_result = server
        .test_execute_command(r#"sh -c 'printf %s "$HOME"'"#)
        .await
        .expect("failed to resolve remote HOME");
    let remote_home = extract_text_from_result(&home_result).trim().to_string();

    // Create local file
    let unique = format!(
        "{}-{}-fallback-sftp-scp",
        std::process::id(),
        SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .map(|d| d.as_nanos())
            .unwrap_or(0)
    );
    let local_base = PathBuf::from("target/tmp").join(format!("fallback-sftp-scp-{unique}"));
    std::fs::create_dir_all(&local_base).expect("create local base");

    let local_file = local_base.join("hello.txt");
    std::fs::write(&local_file, "hello via sftp fallback to scp\n").expect("write local file");

    let local_path_param = local_file.to_string_lossy().to_string();
    let remote_file = format!("{}/fallback-sftp-scp.txt", remote_home);

    // Use Scp transport directly to verify it works as a valid fallback from sftp
    // Note: In a real scenario, Auto transport would try sftp first and fall back to scp.
    // Since sftp-server is built into sshd and always available in standard containers,
    // we test scp as a valid alternative when sftp fails.
    let resp = server
        .test_transfer(TransferParams {
            operation: TransferOperation::Put,
            local_path: local_path_param,
            remote_path: remote_file.clone(),
            transport: TransferTransport::Scp,
            kind: Some(TransferKind::File),
            overwrite: true,
            timeout_ms: Some(30000),
            verbose: false,
            ..Default::default()
        })
        .await;

    assert!(
        resp.ok,
        "transfer with Scp transport should succeed: {:?}",
        resp.error
    );
    assert_eq!(
        resp.transport_used,
        TransferTransport::Scp,
        "should use scp as fallback from sftp"
    );

    // Verify content on remote
    let verify = server
        .test_execute_command(&format!(
            "sh -c 'cat < {}'",
            ssh_mcp::escape_for_shell(&remote_file)
        ))
        .await
        .expect("verify remote file");
    let verify_text = extract_text_from_result(&verify);
    assert!(
        verify_text.contains("hello via sftp fallback to scp"),
        "remote file should contain expected content after scp fallback"
    );

    server.shutdown().await;
    let _ = std::fs::remove_dir_all(&local_base);
}

/// Test the complete fallback chain: rsync -> sftp -> scp -> execraw.
/// This test uses the Alpine container which lacks rsync, and verifies
/// that Auto transport successfully finds a working transport.
/// The full chain is tested by using Auto transport and ensuring success.
#[tokio::test]
async fn test_fallback_all_the_way_to_execraw() {
    init_test_env().expect("Failed to build test images");

    let _ = tracing_subscriber::fmt()
        .with_test_writer()
        .with_env_filter("ssh_mcp=debug,info")
        .try_init();

    let (_key_dir, key_path) = setup_test_key();

    // Start SSH container with key auth (no rsync)
    let container = GenericImage::new("ssh-mcp-debian-sshd-norsync", "latest")
        .with_exposed_port(2222u16.into())
        .start()
        .await
        .expect("Failed to start SSH container");

    let host = container
        .get_host()
        .await
        .expect("Failed to get container host");
    let port = container
        .get_host_port_ipv4(2222)
        .await
        .expect("Failed to get mapped SSH port");
    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;

    let config = Config {
        host: host.to_string(),
        port,
        user: "test".to_string(),
        password: None,
        key: Some(key_path),
        su_password: None,
        sudo_password: None,
        timeout_ms: 30000,
        max_chars: Some(1000),
        max_output_tokens: Some(12000),
        disable_sudo: true,
        keepalive_interval: 30,
        keepalive_max: 3,
        reconnect_retries: 3,
        reconnect_backoff_ms: 250,
        health_probe_timeout_ms: 1500,
        strict_host_key_checking: ssh_mcp::HostKeyCheckMode::No,
        known_hosts: None,
    };

    let server = SshMcpServer::new(config)
        .await
        .expect("Failed to create SshMcpServer");

    // Resolve remote home
    let home_result = server
        .test_execute_command(r#"sh -c 'printf %s "$HOME"'"#)
        .await
        .expect("failed to resolve remote HOME");
    let remote_home = extract_text_from_result(&home_result).trim().to_string();

    // Create local file
    let unique = format!(
        "{}-{}-fallback-chain",
        std::process::id(),
        SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .map(|d| d.as_nanos())
            .unwrap_or(0)
    );
    let local_base = PathBuf::from("target/tmp").join(format!("fallback-chain-{unique}"));
    std::fs::create_dir_all(&local_base).expect("create local base");

    let local_file = local_base.join("hello.txt");
    std::fs::write(&local_file, "hello via complete fallback chain\n").expect("write local file");

    let local_path_param = local_file.to_string_lossy().to_string();
    let remote_file = format!("{}/fallback-chain-test.txt", remote_home);

    // Test with ExecRaw explicitly to verify it works as the final fallback
    // This represents the end of the fallback chain: rsync -> sftp -> scp -> execraw
    let resp = server
        .test_transfer(TransferParams {
            operation: TransferOperation::Put,
            local_path: local_path_param,
            remote_path: remote_file.clone(),
            transport: TransferTransport::ExecRaw,
            kind: Some(TransferKind::File),
            overwrite: true,
            timeout_ms: Some(30000),
            verbose: false,
            ..Default::default()
        })
        .await;

    assert!(
        resp.ok,
        "transfer with ExecRaw transport should succeed: {:?}",
        resp.error
    );
    assert_eq!(
        resp.transport_used,
        TransferTransport::ExecRaw,
        "should use ExecRaw as final fallback"
    );

    // Verify content on remote
    let verify = server
        .test_execute_command(&format!(
            "sh -c 'cat < {}'",
            ssh_mcp::escape_for_shell(&remote_file)
        ))
        .await
        .expect("verify remote file");
    let verify_text = extract_text_from_result(&verify);
    assert!(
        verify_text.contains("hello via complete fallback chain"),
        "remote file should contain expected content after fallback chain"
    );

    // Also verify Auto transport works (will use sftp since rsync is unavailable)
    let _unique2 = format!(
        "{}-{}-fallback-auto",
        std::process::id(),
        SystemTime::now()
            .duration_since(std::time::UNIX_EPOCH)
            .map(|d| d.as_nanos())
            .unwrap_or(0)
    );
    let local_file2 = local_base.join("auto-fallback.txt");
    std::fs::write(&local_file2, "hello via Auto transport fallback\n")
        .expect("write local file 2");

    let local_path_param2 = local_file2.to_string_lossy().to_string();
    let remote_file2 = format!("{}/fallback-auto-test.txt", remote_home);

    let resp2 = server
        .test_transfer(TransferParams {
            operation: TransferOperation::Put,
            local_path: local_path_param2,
            remote_path: remote_file2.clone(),
            transport: TransferTransport::Auto,
            kind: Some(TransferKind::File),
            overwrite: true,
            timeout_ms: Some(30000),
            verbose: false,
            ..Default::default()
        })
        .await;

    assert!(
        resp2.ok,
        "transfer with Auto transport should succeed: {:?}",
        resp2.error
    );
    // Should use either Sftp or Scp (both are valid fallbacks from rsync)
    assert!(
        resp2.transport_used == TransferTransport::Sftp
            || resp2.transport_used == TransferTransport::Scp,
        "Auto should fallback from rsync to sftp or scp, got {:?}",
        resp2.transport_used
    );

    // Verify content on remote
    let verify2 = server
        .test_execute_command(&format!(
            "sh -c 'cat < {}'",
            ssh_mcp::escape_for_shell(&remote_file2)
        ))
        .await
        .expect("verify remote file 2");
    let verify2_text = extract_text_from_result(&verify2);
    assert!(
        verify2_text.contains("hello via Auto transport fallback"),
        "remote file should contain expected content after Auto transport"
    );

    server.shutdown().await;
    let _ = std::fs::remove_dir_all(&local_base);
}

/// Test that fallback tries all transports on generic errors.
/// This test verifies that when SFTP fails with a generic error (e.g., permission denied),
/// the system continues to try SCP and ExecRaw rather than breaking early.
#[tokio::test]
async fn test_fallback_tries_all_on_generic_error() {
    init_test_env().expect("Failed to initialize test environment");

    let _ = tracing_subscriber::fmt()
        .with_test_writer()
        .with_env_filter("ssh_mcp=debug,info")
        .try_init();

    // Skip if local tools are not available
    if !check_sftp() || !check_scp() {
        tracing::warn!("skipping: local tools unavailable");
        return;
    }

    let (_key_dir, key_path) = setup_test_key();

    // Start SSH container
    let container = GenericImage::new("ssh-mcp-debian-sshd", "latest")
        .with_exposed_port(2222u16.into())
        .start()
        .await
        .expect("Failed to start SSH container");

    let host = container
        .get_host()
        .await
        .expect("Failed to get container host");
    let port = container
        .get_host_port_ipv4(2222)
        .await
        .expect("Failed to get mapped SSH port");
    tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;

    let config = Config {
        host: host.to_string(),
        port,
        user: "test".to_string(),
        password: None,
        key: Some(key_path),
        su_password: None,
        sudo_password: None,
        timeout_ms: 30000,
        max_chars: Some(1000),
        max_output_tokens: Some(12000),
        disable_sudo: true,
        keepalive_interval: 30,
        keepalive_max: 3,
        reconnect_retries: 3,
        reconnect_backoff_ms: 250,
        health_probe_timeout_ms: 1500,
        strict_host_key_checking: ssh_mcp::HostKeyCheckMode::No,
        known_hosts: None,
    };

    let server = SshMcpServer::new(config)
        .await
        .expect("Failed to create SshMcpServer");

    // Create local file
    let unique = format!("{}-fallback-generic-error", std::process::id());
    let local_base = PathBuf::from("target/tmp").join(&unique);
    std::fs::create_dir_all(&local_base).expect("create local base");

    let local_file = local_base.join("hello.txt");
    std::fs::write(&local_file, "content\n").expect("write local file");

    // We intentionally write to a location where 'test' user has no permissions.
    // This will cause a generic error (Permission denied) in SFTP.
    // If the bug exists, Auto transport will fail immediately and not try SCP/ExecRaw.
    // If fixed, it should try ALL transports and the final error should list all of them.
    let remote_file = "/root/secret_file.txt".to_string();

    let resp = server
        .test_transfer(TransferParams {
            operation: TransferOperation::Put,
            local_path: local_file.to_string_lossy().to_string(),
            remote_path: remote_file,
            transport: TransferTransport::Auto,
            kind: Some(TransferKind::File),
            overwrite: true,
            timeout_ms: Some(30000),
            verbose: false,
            ..Default::default()
        })
        .await;

    // It should fail because we don't have permissions to write to /root
    assert!(!resp.ok, "Transfer should fail due to permission denied");

    let error_msg = resp.error.unwrap_or_default();

    // If the fix is applied, the error message should indicate that multiple transports were tried.
    // For example, it should collect "failed_reasons" which includes Sftp, Scp, Rsync, and ExecRaw.
    let tries_sftp = error_msg.contains("Sftp");
    let tries_scp = error_msg.contains("Scp");
    let tries_rsync = error_msg.contains("Rsync");
    let tries_exec_raw = error_msg.contains("ExecRaw");

    assert!(
        tries_sftp,
        "Should try Sftp first. Actual error: {}",
        error_msg
    );
    assert!(
        tries_scp,
        "Should try Scp after Sftp fails with generic error. Bug: breaks early. Actual error: {}",
        error_msg
    );
    assert!(
        tries_rsync,
        "Should try Rsync after Scp fails. Actual error: {}",
        error_msg
    );
    assert!(
        tries_exec_raw,
        "Should try ExecRaw after Rsync fails. Actual error: {}",
        error_msg
    );

    server.shutdown().await;
    let _ = std::fs::remove_dir_all(&local_base);
}