aboutsummaryrefslogtreecommitdiff
path: root/networking/ftpgetput.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-02-06 15:48:12 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-06 15:48:12 +0100
commit1783ffa990814e2aac14e7ff5a4bbf2d5bebe3cc (patch)
tree7e792db0260222476ec186db33fec49a22039731 /networking/ftpgetput.c
parent403f2999f94937ba3f37db6d093832f636815bb9 (diff)
downloadbusybox-w32-1783ffa990814e2aac14e7ff5a4bbf2d5bebe3cc.tar.gz
busybox-w32-1783ffa990814e2aac14e7ff5a4bbf2d5bebe3cc.tar.bz2
busybox-w32-1783ffa990814e2aac14e7ff5a4bbf2d5bebe3cc.zip
wget: add EPSV support
function old new delta parse_pasv_epsv - 151 +151 wget_main 2440 2382 -58 xconnect_ftpdata 223 94 -129 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 0/2 up/down: 151/-187) Total: -36 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ftpgetput.c')
-rw-r--r--networking/ftpgetput.c57
1 files changed, 8 insertions, 49 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index 697955e82..cdad629da 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -152,57 +152,16 @@ static void ftp_login(void)
152 152
153static int xconnect_ftpdata(void) 153static int xconnect_ftpdata(void)
154{ 154{
155 char *buf_ptr; 155 int port_num;
156 unsigned port_num;
157 156
158/* 157 if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL) == 229) {
159PASV command will not work for IPv6. RFC2428 describes 158 /* good */
160IPv6-capable "extended PASV" - EPSV. 159 } else if (ftpcmd("PASV", NULL) != 227) {
161 160 ftp_die("PASV");
162"EPSV [protocol]" asks server to bind to and listen on a data port
163in specified protocol. Protocol is 1 for IPv4, 2 for IPv6.
164If not specified, defaults to "same as used for control connection".
165If server understood you, it should answer "229 <some text>(|||port|)"
166where "|" are literal pipe chars and "port" is ASCII decimal port#.
167
168There is also an IPv6-capable replacement for PORT (EPRT),
169but we don't need that.
170
171NB: PASV may still work for some servers even over IPv6.
172For example, vsftp happily answers
173"227 Entering Passive Mode (0,0,0,0,n,n)" and proceeds as usual.
174*/
175 if (!ENABLE_FEATURE_IPV6
176 || ftpcmd("EPSV", NULL) != 229
177 ) {
178/* maybe also go straight to PAST if lsa->u.sa.sa_family == AF_INET? */
179 if (ftpcmd("PASV", NULL) != 227) {
180 ftp_die("PASV");
181 }
182
183 /* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage]"
184 * Server's IP is N1.N2.N3.N4 (we ignore it)
185 * Server's port for data connection is P1*256+P2 */
186 buf_ptr = strrchr(buf, ')');
187 if (buf_ptr) *buf_ptr = '\0';
188
189 buf_ptr = strrchr(buf, ',');
190 *buf_ptr = '\0';
191 port_num = xatoul_range(buf_ptr + 1, 0, 255);
192
193 buf_ptr = strrchr(buf, ',');
194 *buf_ptr = '\0';
195 port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256;
196 } else {
197 /* Response is "NNN garbage(|||P1|)"
198 * Server's port for data connection is P1 */
199 buf_ptr = strrchr(buf, '|');
200 if (buf_ptr) *buf_ptr = '\0';
201
202 buf_ptr = strrchr(buf, '|');
203 *buf_ptr = '\0';
204 port_num = xatoul_range(buf_ptr + 1, 0, 65535);
205 } 161 }
162 port_num = parse_pasv_epsv(buf);
163 if (port_num < 0)
164 ftp_die("PASV");
206 165
207 set_nport(&lsa->u.sa, htons(port_num)); 166 set_nport(&lsa->u.sa, htons(port_num));
208 return xconnect_stream(lsa); 167 return xconnect_stream(lsa);