Skip to content

Commit afcf2df

Browse files
17decmattnenterprise
authored andcommitted
Drop data connection early in FtpStream.list_command() (#55)
Fixes issue #54. The problem is that we're expecting to read a response from the server on the control connection, but the server will only send a response when the data connection has been properly closed. We can ensure this by dropping the data connection before reading the server response.
1 parent b3c10e9 commit afcf2df

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/ftp.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,19 @@ impl FtpStream {
372372

373373
/// Execute a command which returns list of strings in a separate stream
374374
fn list_command(&mut self, cmd: String, open_code: u32, close_code: u32) -> Result<Vec<String>> {
375-
let mut data_stream = BufReader::new(try!(self.data_command(&cmd)));
376-
try!(self.read_response_in(&[open_code, status::ALREADY_OPEN]));
377-
378375
let mut lines: Vec<String> = Vec::new();
379-
let mut line = String::new();
380-
loop {
381-
match data_stream.read_to_string(&mut line) {
382-
Ok(0) => break,
383-
Ok(_) => lines.extend(line.split("\r\n").into_iter().map(|s| String::from(s)).filter(|s| s.len() > 0)),
384-
Err(err) => return Err(FtpError::ConnectionError(err)),
385-
};
376+
{
377+
let mut data_stream = BufReader::new(try!(self.data_command(&cmd)));
378+
try!(self.read_response_in(&[open_code, status::ALREADY_OPEN]));
379+
380+
let mut line = String::new();
381+
loop {
382+
match data_stream.read_to_string(&mut line) {
383+
Ok(0) => break,
384+
Ok(_) => lines.extend(line.split("\r\n").into_iter().map(|s| String::from(s)).filter(|s| s.len() > 0)),
385+
Err(err) => return Err(FtpError::ConnectionError(err)),
386+
};
387+
}
386388
}
387389

388390
self.read_response(close_code).map(|_| lines)

0 commit comments

Comments
 (0)