summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-02-08 16:40:34 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-02-09 14:06:28 +0100
commit528f71c2ecdbb03117af226978804148d69a1007 (patch)
tree1345d18162135945aff7657f539071c6b4019437
parent115c9e27f53809a254fba44b023bea92f4d4dcd0 (diff)
downloadcurl-528f71c2ecdbb03117af226978804148d69a1007.tar.gz
ftp: add 'list_only' to the transfer state struct
and rename it from 'ftp_list_only' since it is also used for SSH and POP3. The state is updated internally for 'type=D' FTP URLs. Added test case 1570 to verify. Closes #6578
-rw-r--r--lib/ftp.c8
-rw-r--r--lib/pop3.c2
-rw-r--r--lib/setopt.c2
-rw-r--r--lib/transfer.c1
-rw-r--r--lib/urldata.h5
-rw-r--r--lib/vssh/libssh.c2
-rw-r--r--lib/vssh/libssh2.c2
-rw-r--r--lib/vssh/wolfssh.c2
-rw-r--r--tests/data/Makefile.inc2
-rw-r--r--tests/data/test157073
10 files changed, 87 insertions, 12 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index 05bed5464..f0ce14c13 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -1378,7 +1378,7 @@ static CURLcode ftp_state_prepare_transfer(struct Curl_easy *data)
result = Curl_pp_sendf(data, &ftpc->pp, "PRET %s",
data->set.str[STRING_CUSTOMREQUEST]?
data->set.str[STRING_CUSTOMREQUEST]:
- (data->set.ftp_list_only?"NLST":"LIST"));
+ (data->state.list_only?"NLST":"LIST"));
else if(data->set.upload)
result = Curl_pp_sendf(data, &ftpc->pp, "PRET STOR %s",
conn->proto.ftpc.file);
@@ -1485,7 +1485,7 @@ static CURLcode ftp_state_list(struct Curl_easy *data)
cmd = aprintf("%s%s%s",
data->set.str[STRING_CUSTOMREQUEST]?
data->set.str[STRING_CUSTOMREQUEST]:
- (data->set.ftp_list_only?"NLST":"LIST"),
+ (data->state.list_only?"NLST":"LIST"),
lstArg? " ": "",
lstArg? lstArg: "");
free(lstArg);
@@ -3648,7 +3648,7 @@ static CURLcode ftp_do_more(struct Curl_easy *data, int *completep)
if(result)
;
- else if(data->set.ftp_list_only || !ftpc->file) {
+ else if(data->state.list_only || !ftpc->file) {
/* The specified path ends with a slash, and therefore we think this
is a directory that is requested, use LIST. But before that we
need to set ASCII transfer mode. */
@@ -4356,7 +4356,7 @@ static CURLcode ftp_setup_connection(struct Curl_easy *data,
break;
case 'D': /* directory mode */
- data->set.ftp_list_only = TRUE;
+ data->state.list_only = TRUE;
break;
case 'I': /* binary mode */
diff --git a/lib/pop3.c b/lib/pop3.c
index b8e7698a4..ccfebd02a 100644
--- a/lib/pop3.c
+++ b/lib/pop3.c
@@ -571,7 +571,7 @@ static CURLcode pop3_perform_command(struct Curl_easy *data)
const char *command = NULL;
/* Calculate the default command */
- if(pop3->id[0] == '\0' || data->set.ftp_list_only) {
+ if(pop3->id[0] == '\0' || data->set.list_only) {
command = "LIST";
if(pop3->id[0] != '\0')
diff --git a/lib/setopt.c b/lib/setopt.c
index 4e0cbc3f8..715b2f284 100644
--- a/lib/setopt.c
+++ b/lib/setopt.c
@@ -1157,7 +1157,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
* An option that changes the command to one that asks for a list only, no
* file info details. Used for FTP, POP3 and SFTP.
*/
- data->set.ftp_list_only = (0 != va_arg(param, long)) ? TRUE : FALSE;
+ data->set.list_only = (0 != va_arg(param, long)) ? TRUE : FALSE;
break;
case CURLOPT_APPEND:
diff --git a/lib/transfer.c b/lib/transfer.c
index e63ad7133..c3b2d11a2 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -1416,6 +1416,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
}
data->state.prefer_ascii = data->set.prefer_ascii;
+ data->state.list_only = data->set.list_only;
data->state.httpreq = data->set.method;
data->change.url = data->set.str[STRING_SET_URL];
diff --git a/lib/urldata.h b/lib/urldata.h
index 00c7d407f..6a9c52c44 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1467,7 +1467,8 @@ struct UrlState {
BIT(stream_depends_e); /* set or don't set the Exclusive bit */
BIT(previouslypending); /* this transfer WAS in the multi->pending queue */
BIT(cookie_engine);
- BIT(prefer_ascii); /* ASCII rather than binary */
+ BIT(prefer_ascii); /* ASCII rather than binary */
+ BIT(list_only); /* list directory contents */
};
@@ -1807,7 +1808,7 @@ struct UserDefined {
BIT(tunnel_thru_httpproxy); /* use CONNECT through a HTTP proxy */
BIT(prefer_ascii); /* ASCII rather than binary */
BIT(remote_append); /* append, not overwrite, on upload */
- BIT(ftp_list_only); /* switch FTP command for listing directories */
+ BIT(list_only); /* list directory */
#ifndef CURL_DISABLE_FTP
BIT(ftp_use_port); /* use the FTP PORT command */
BIT(ftp_use_epsv); /* if EPSV is to be attempted or not */
diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c
index dfdef12af..1bb644eed 100644
--- a/lib/vssh/libssh.c
+++ b/lib/vssh/libssh.c
@@ -1413,7 +1413,7 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
sshc->readdir_longentry = sshc->readdir_attrs->longname;
sshc->readdir_len = strlen(sshc->readdir_filename);
- if(data->set.ftp_list_only) {
+ if(data->set.list_only) {
char *tmpLine;
tmpLine = aprintf("%s\n", sshc->readdir_filename);
diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c
index dbbeb2322..0e7c2eb98 100644
--- a/lib/vssh/libssh2.c
+++ b/lib/vssh/libssh2.c
@@ -2143,7 +2143,7 @@ static CURLcode ssh_statemach_act(struct Curl_easy *data, bool *block)
readdir_len = (size_t) rc;
sshp->readdir_filename[readdir_len] = '\0';
- if(data->set.ftp_list_only) {
+ if(data->set.list_only) {
result = Curl_client_write(data, CLIENTWRITE_BODY,
sshp->readdir_filename,
readdir_len);
diff --git a/lib/vssh/wolfssh.c b/lib/vssh/wolfssh.c
index c0de33984..de0b1c777 100644
--- a/lib/vssh/wolfssh.c
+++ b/lib/vssh/wolfssh.c
@@ -859,7 +859,7 @@ static CURLcode wssh_statemach_act(struct Curl_easy *data, bool *block)
result = CURLE_OK;
while(name) {
char *line = aprintf("%s\n",
- data->set.ftp_list_only ?
+ data->set.list_only ?
name->fName : name->lName);
if(line == NULL) {
state(data, SSH_SFTP_CLOSE);
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
index 228e93d80..9667369b2 100644
--- a/tests/data/Makefile.inc
+++ b/tests/data/Makefile.inc
@@ -187,7 +187,7 @@ test1540 \
\
test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 \
test1558 test1559 test1560 test1561 test1562 test1563 test1564 test1565 \
-test1566 test1567 test1568 test1569 \
+test1566 test1567 test1568 test1569 test1570 \
\
test1590 test1591 test1592 test1593 test1594 test1595 test1596 \
\
diff --git a/tests/data/test1570 b/tests/data/test1570
new file mode 100644
index 000000000..fd0c27395
--- /dev/null
+++ b/tests/data/test1570
@@ -0,0 +1,73 @@
+<testcase>
+<info>
+<keywords>
+FTP
+PASV
+RETR
+</keywords>
+</info>
+# Server-side
+<reply>
+<data nocheck="yes">
+data
+ to
+ see
+that FTP
+works
+ so does it?
+</data>
+<servercmd>
+REPLY EPSV 500 no such command
+</servercmd>
+</reply>
+
+# Client-side
+<client>
+<server>
+ftp
+</server>
+ <name>
+FTP first type=D then regular URL
+ </name>
+<tool>
+lib1569
+</tool>
+<command>
+"ftp://%HOSTIP:%FTPPORT/1570;type=D" ftp://%HOSTIP:%FTPPORT/1570
+</command>
+
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+USER anonymous
+PASS ftp@example.com
+PWD
+EPSV
+PASV
+TYPE A
+NLST
+PASV
+TYPE I
+SIZE 1570
+RETR 1570
+QUIT
+</protocol>
+</verify>
+<stdout>
+data
+ to
+ see
+that FTP
+works
+ so does it?
+data
+ to
+ see
+that FTP
+works
+ so does it?
+</stdout>
+
+</testcase>