Welcome messages

This commit is contained in:
ChristianVisintin
2020-12-04 14:00:23 +01:00
parent 809b3b8d99
commit 82a19dd089
4 changed files with 15 additions and 6 deletions

View File

@@ -225,7 +225,7 @@ impl FileTransfer for FtpFileTransfer {
port: u16, port: u16,
username: Option<String>, username: Option<String>,
password: Option<String>, password: Option<String>,
) -> Result<(), FileTransferError> { ) -> Result<Option<String>, FileTransferError> {
// Get stream // Get stream
let mut stream: FtpStream = match FtpStream::connect(format!("{}:{}", address, port)) { let mut stream: FtpStream = match FtpStream::connect(format!("{}:{}", address, port)) {
Ok(stream) => stream, Ok(stream) => stream,
@@ -273,7 +273,7 @@ impl FileTransfer for FtpFileTransfer {
// Set stream // Set stream
self.stream = Some(stream); self.stream = Some(stream);
// Return OK // Return OK
Ok(()) Ok(self.stream.as_ref().unwrap().get_welcome_msg())
} }
/// ### disconnect /// ### disconnect

View File

@@ -127,6 +127,7 @@ pub trait FileTransfer {
/// ### connect /// ### connect
/// ///
/// Connect to the remote server /// Connect to the remote server
/// Can return banner / welcome message on success
fn connect( fn connect(
&mut self, &mut self,
@@ -134,7 +135,7 @@ pub trait FileTransfer {
port: u16, port: u16,
username: Option<String>, username: Option<String>,
password: Option<String>, password: Option<String>,
) -> Result<(), FileTransferError>; ) -> Result<Option<String>, FileTransferError>;
/// ### disconnect /// ### disconnect
/// ///

View File

@@ -195,7 +195,7 @@ impl FileTransfer for SftpFileTransfer {
port: u16, port: u16,
username: Option<String>, username: Option<String>,
password: Option<String>, password: Option<String>,
) -> Result<(), FileTransferError> { ) -> Result<Option<String>, FileTransferError> {
// Setup tcp stream // Setup tcp stream
let tcp: TcpStream = match TcpStream::connect(format!("{}:{}", address, port)) { let tcp: TcpStream = match TcpStream::connect(format!("{}:{}", address, port)) {
Ok(stream) => stream, Ok(stream) => stream,
@@ -258,10 +258,14 @@ impl FileTransfer for SftpFileTransfer {
} }
}; };
// Set session // Set session
let banner: Option<String> = match session.banner() {
Some(s) => Some(String::from(s)),
None => None,
};
self.session = Some(session); self.session = Some(session);
// Set sftp // Set sftp
self.sftp = Some(sftp); self.sftp = Some(sftp);
Ok(()) Ok(banner)
} }
/// ### disconnect /// ### disconnect

View File

@@ -38,7 +38,11 @@ impl FileTransferActivity {
self.params.username.clone(), self.params.username.clone(),
self.params.password.clone(), self.params.password.clone(),
) { ) {
Ok(_) => { Ok(welcome) => {
if let Some(banner) = welcome {
// Log welcome
self.log(LogLevel::Info, format!("Established connection with '{}': \"{}\"", self.params.address, banner).as_ref());
}
// Set state to explorer // Set state to explorer
self.input_mode = InputMode::Explorer; self.input_mode = InputMode::Explorer;
self.reload_remote_dir(); self.reload_remote_dir();