//! ## Parser Port Helpers //! //! Shared helpers for resolving default protocol ports and parsing explicit //! port captures from remote connection strings. use crate::filetransfer::FileTransferProtocol; pub(super) fn default_port_for_protocol(protocol: FileTransferProtocol) -> u16 { match protocol { FileTransferProtocol::Ftp(_) => 21, FileTransferProtocol::Scp | FileTransferProtocol::Sftp => 22, _ => 22, } } pub(super) fn parse_port(port: Option>, default: u16) -> Result { match port { Some(port) => port .as_str() .parse::() .map_err(|err| format!("Bad port \"{}\": {err}", port.as_str())), None => Ok(default), } }