From feb3f21b34e0ec6275fdecaecc4069adc9dabb1d Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sat, 27 Jan 2007 10:05:40 +0100 Subject: [PATCH] ftp: ftp didn't handle filenames with spaces. [ Bug 942; backported from commit 3f4de99f16ac819f292ca568095d7032d88e5a8b in ELinks 0.12.GIT. I omitted the part of the patch that decodes FTP URLs for HTML TITLE, because I think it's an enhancement rather than a bug fix. --KON ] --- src/protocol/ftp/ftp.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/protocol/ftp/ftp.c b/src/protocol/ftp/ftp.c index 91243681c..a4be62f0b 100644 --- a/src/protocol/ftp/ftp.c +++ b/src/protocol/ftp/ftp.c @@ -682,8 +682,15 @@ add_file_cmd_to_str(struct connection *conn) if (!conn->uri->datalen || conn->uri->data[conn->uri->datalen - 1] == '/') { + struct string uri_string; /* Commands to get directory listing. */ + if (!init_string(&uri_string)) { + done_string(&command); + done_string(&ftp_data_command); + abort_connection(conn, S_OUT_OF_MEM); + return NULL; + } ftp->dir = 1; ftp->pending_commands = 4; @@ -694,17 +701,27 @@ add_file_cmd_to_str(struct connection *conn) add_string_to_string(&command, &ftp_data_command); add_to_string(&command, "CWD "); - add_uri_to_string(&command, conn->uri, URI_PATH); + add_uri_to_string(&uri_string, conn->uri, URI_PATH); + decode_uri_string(&uri_string); + add_string_to_string(&command, &uri_string); add_crlf_to_string(&command); add_to_string(&command, "LIST"); add_crlf_to_string(&command); + done_string(&uri_string); conn->from = 0; } else { + struct string uri_string; /* Commands to get a file. */ + if (!init_string(&uri_string)) { + done_string(&command); + done_string(&ftp_data_command); + abort_connection(conn, S_OUT_OF_MEM); + return NULL; + } ftp->dir = 0; ftp->pending_commands = 3; @@ -726,8 +743,11 @@ add_file_cmd_to_str(struct connection *conn) } add_to_string(&command, "RETR "); - add_uri_to_string(&command, conn->uri, URI_PATH); + add_uri_to_string(&uri_string, conn->uri, URI_PATH); + decode_uri_string(&uri_string); + add_string_to_string(&command, &uri_string); add_crlf_to_string(&command); + done_string(&uri_string); } done_string(&ftp_data_command); @@ -1107,7 +1127,7 @@ display_dir_entry(struct cache_entry *cached, off_t *pos, int *tries, } add_to_string(&string, "name.source, ftp_info->name.length); + encode_uri_string(&string, ftp_info->name.source, ftp_info->name.length, 0); if (ftp_info->type == FTP_FILE_DIRECTORY) add_char_to_string(&string, '/'); add_to_string(&string, "\">");