pu369com

如何用rust复制局域网共享文件夹中的文件

内置copy

use std::fs::File;
use std::io::copy;

fn main() -> std::io::Result<()> {
    let mut source_file = File::open(r"\\192.168.2.2\共享文件\source.db")?;
    let mut dest_file = File::create("dest.db")?;

    copy(&mut source_file, &mut dest_file)?;

    Ok(())
}

或者cmd命令

use std::process::Command;

fn main() -> std::io::Result<()> {
       
        Command::new("net")
            .args(&["use", r"\\192.168.2.2", "/user:guest",""])
            .status()?;
        
        Command::new("cmd")
            .args(&["/C", &format!("echo {} >> \\\\192.168.2.2\\共享文件\\log\\log.txt", 135246)])
            .status()?;

    Ok(())
}

 

posted on 2025-07-18 15:42  pu369com  阅读(22)  评论(0)    收藏  举报

导航