Skip to content

Error when listing directories containing spaces in their names #530

@Ryan-Blignaut

Description

@Ryan-Blignaut

When trying to list items in a directory with a space in the file name data after the space gets truncated.
I have created a small test for this:

use unftp_sbe_fs::ServerExt;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    pretty_env_logger::init();
    let addr = "127.0.0.1:2121";
    let server = libunftp::Server::with_fs("./test/").build().unwrap();
    println!("Starting ftp server on {}", addr);
    server.listen(addr).await.unwrap();
}

#[cfg(test)]
mod tests {

    #[test]
    fn test_list_item_with_space() {
        pretty_env_logger::init();
        use ftp::FtpStream;
        let mut ftp_stream =
            FtpStream::connect("localhost:2121").unwrap_or_else(|err| panic!("{}", err));
        ftp_stream.login("anonymous", "anonymous").unwrap();

        let folder_name_with_space = "test with space";
        // Make test folder as well as subfolder
        ftp_stream.mkdir(folder_name_with_space).unwrap();
        ftp_stream.mkdir(format!("{}/{}", folder_name_with_space, "cool").as_str()).unwrap();

        ftp_stream
            .list(folder_name_with_space.into())
            .unwrap()
            .iter()
            .for_each(|item| {
                println!("{:?}", item);
            });

        let _ = ftp_stream.quit();
    }
}

The expected output of the print statement would be something along the lines of:
"drwxr-xr-x 1 0 0 0 Jan 18 21:30 cool"

However test fails with an error of:
InvalidResponse("Expected code [226, 250], got response: 550 File not found\r\n")

It looks like from the logs the path got truncated:
DEBUG libunftp::server::datachan > Data channel command received: List { options: None, path: Some("test") }, username: anonymous, source: 127.0.0.1:58510, trace-id: 0xbc8265330a20d513, path: test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions