Skip to content

[QUESTION] - pwd() fails with BadResponse on Altervista FTP (unexpected server response format) #113

@Angelk90

Description

@Angelk90

Hi @veeso, congratulations on the project.

I'm trying the code, but I'm having problems.
I can connect because I can see the file list.

It seems the server is returning a response in a format the parser doesn't accept.
Would it be possible to expose the raw response for inspection or make pwd() more flexible during parsing?

get_welcome_msg doesn't work either.

--- Server Features ---
SIZE
PBSZ
AUTH TLS
SPSV
TVFS
MLSD
REST STREAM
MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
PASV
UTF8
IDLE
EPRT
MFMT
PROT
EPSV
ESTP
ESTA
PRET
MDTM
------------------------

edit:

I connected via "nc name.altervista.org 21"

When I asked for PWD it said:
257 "/" � la tua locazione corrente

result:

Connected (TLS): welcome message not UTF-8 (ignored).
FTPS login successful as ....
PWD failed with error: BadResponse
Directory content:
drwxrwxr-x    2 ....    membri           4096 Aug 26 13:52 aaaa
....

code:

[dependencies]
suppaftp = { version = "6", features = ["native-tls"] }
use suppaftp::native_tls::TlsConnector;
use suppaftp::NativeTlsConnector;
use suppaftp::NativeTlsFtpStream;
use suppaftp::FtpError;
use std::time::Duration;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let host = "name.altervista.org";
    let port = 21;
    let user = "name";
    let pass = "pass";

    let ftp_plain = NativeTlsFtpStream::connect((host, port))?;
    ftp_plain.get_ref().set_read_timeout(Some(Duration::from_secs(10)))?;
    ftp_plain.get_ref().set_write_timeout(Some(Duration::from_secs(10)))?;

    let tls = NativeTlsConnector::from(TlsConnector::new()?);
    let mut ftp = ftp_plain.into_secure(tls, host)?;

    if let Some(welcome) = ftp.get_welcome_msg() {
        println!("Welcome: {}", welcome);
    } else {
        println!("Connected (TLS): welcome message not UTF-8 (ignored).");
    }

    match ftp.login(user, pass) {
        Ok(_) => {
            println!("FTPS login successful as {}", user);
        }
        Err(FtpError::UnexpectedResponse(resp)) => {
            println!("Login failed. Code: {:?}", resp.status);
            println!("Message (lossy): {}", String::from_utf8_lossy(&resp.body));
            return Ok(());
        }
        Err(e) => {
            println!("Connection/login error: {:?}", e);
            return Ok(());
        }
    }

    match ftp.pwd() {
        Ok(dir) => println!("Current directory: {}", dir),
        Err(FtpError::UnexpectedResponse(resp)) => {
            println!("PWD failed. Status: {:?}", resp.status);
            println!("Raw PWD response (lossy): {}", String::from_utf8_lossy(&resp.body));
        }
        Err(e) => {
            println!("PWD failed with error: {:?}", e);
        }
    }

    match ftp.list(None) {
        Ok(list) => {
            println!("Directory content:");
            for entry in list {
                println!("{}", entry);
            }
        }
        Err(e) => {
            println!("LIST failed: {:?}", e);
        }
    }

    ftp.quit()?;
    Ok(())
}

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions