Skip to content
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

list and nlst commands always return an error #64

Open
Luxed opened this issue Oct 6, 2017 · 2 comments
Open

list and nlst commands always return an error #64

Luxed opened this issue Oct 6, 2017 · 2 comments

Comments

@Luxed
Copy link
Contributor

Luxed commented Oct 6, 2017

I'm using Ubuntu server 16.04.

Program:

extern crate ftp;

use ftp::openssl::ssl::*;

fn main() {
    let ftp_stream = ftp::FtpStream::connect("127.0.0.1:21").unwrap();
    let ctx = SslContext::new(SslMethod::Sslv23).unwrap();
    let ssl = Ssl::new(&ctx).unwrap();

    // Switch to the secure mode
    let mut ftp_stream = ftp_stream.into_secure(ssl).unwrap();

    ftp_stream.login("account", "passwd").unwrap();

    let v_list = ftp_stream.nlst(Some("/")).unwrap();

    let _ = ftp_stream.quit();
}

Error:
thread 'main' panicked at 'called Result::unwrap() on an Err value: InvalidResponse("error: could not parse reply code: invalid digit found in string")', /checkout/src/libcore/result.rs:860:4

I tried with other values or even None for list() and nlst() with no luck. cwd() and pwd() work.

@Luxed
Copy link
Contributor Author

Luxed commented Oct 26, 2017

Found the error (or at least I think so):
When I try to get the list of directories, the program asks for PASV mode (which crashes if my server doesn't have it enabled so that's another issue(maybe... I just saw that it is better to use PASV at all times)) and then gets the line. But it reads the 3 first characters of the line to get the response code. issue is: in a "ls" command, there are no response code (or at least it works like this for me)

@Luxed
Copy link
Contributor Author

Luxed commented Oct 27, 2017

Well,
After some trying I got a way to stock the SocketAddr in the FtpStream structure. the issue is that now, I get another error: SecureError: The underlying stream reported an error

Edit 1: More understanding of the way it works: apparently PASV needs to be passed before each command ?

Edit 2: The library crashes on the second PASV command because it cannot read the response code.
(I'm only documenting what I find, it makes it easier for me)

Edit 3: The second time a PASV is done, it reads an error from the last command ????
Here is what happens:

  • I exectute the list function
  • it gives me the list of files and directories (all good)
  • I try to get the list once again
  • it tries to go into PASV mode
  • Exectutes read_response_in
  • Returns an error because it reads: "Error trying to get a list of files"

It's weird because it actually returned me what I wanted the first time !!

Edit 4: I can confirm that the second PASV is the issue here... but the first pasv doesn't give me any code, only the list... Maybe my ftp server is the issue, I will have to try on more computers/servers to know for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant