Skip to content

Always use IP of control conn for data conn #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,28 +264,17 @@ impl FtpStream {
.ok_or_else(|| FtpError::InvalidResponse(format!("Invalid PASV response: {}", line)))
.and_then(|caps| {
// If the regex matches we can be sure groups contains numbers
let (oct1, oct2, oct3, oct4) = (
caps[1].parse::<u8>().unwrap(),
caps[2].parse::<u8>().unwrap(),
caps[3].parse::<u8>().unwrap(),
caps[4].parse::<u8>().unwrap(),
);
let (msb, lsb) = (
caps[5].parse::<u8>().unwrap(),
caps[6].parse::<u8>().unwrap(),
);
let port = ((msb as u16) << 8) + lsb as u16;

use std::net::{IpAddr, Ipv4Addr};

let ip = if (oct1, oct2, oct3, oct4) == (0, 0, 0, 0) {
self.get_ref()
.peer_addr()
.map_err(FtpError::ConnectionError)?
.ip()
} else {
IpAddr::V4(Ipv4Addr::new(oct1, oct2, oct3, oct4))
};
let ip = self
.get_ref()
.peer_addr()
.map_err(FtpError::ConnectionError)?
.ip();
Ok(SocketAddr::new(ip, port))
})
}
Expand Down