quick_file_transfer/
send.rs

1use crate::config::{
2    transfer::send::{SendArgs, SendCommand, SendIpArgs},
3    Config,
4};
5#[cfg(feature = "mdns")]
6use crate::{config::transfer::send::mdns::SendMdnsArgs, mdns::resolve::resolve_mdns_hostname};
7
8use anyhow::Result;
9use client::run_client;
10
11pub mod client;
12pub mod util;
13
14pub fn handle_send_cmd(send_args: &SendArgs, _cfg: &Config) -> Result<()> {
15    match send_args.subcmd {
16        SendCommand::Ip(SendIpArgs {
17            ref ip,
18            port,
19            compression,
20        }) => run_client(
21            ip.parse()?,
22            port,
23            send_args.mmap,
24            send_args.file.as_slice(),
25            send_args.prealloc(),
26            compression,
27            send_args.tcp_connect_mode(),
28            None,
29        )?,
30        #[cfg(feature = "mdns")]
31        SendCommand::Mdns(SendMdnsArgs {
32            ref hostname,
33            timeout_ms,
34            ip_version,
35            port,
36            compression,
37        }) => {
38            if let Some(resolved_info) = resolve_mdns_hostname(hostname, timeout_ms, true)? {
39                if let Some(ip) = resolved_info.get_ip(ip_version) {
40                    run_client(
41                        *ip,
42                        port,
43                        send_args.mmap,
44                        send_args.file.as_slice(),
45                        send_args.prealloc(),
46                        compression,
47                        send_args.tcp_connect_mode(),
48                        None,
49                    )?;
50                }
51            }
52        }
53    }
54    Ok(())
55}