Lines Matching refs:ftp
72 static int ftp_putcmd( ftpbuf_t *ftp,
79 static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len);
80 static int my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len);
81 static int my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen);
84 static int ftp_readline(ftpbuf_t *ftp);
87 static int ftp_getresp(ftpbuf_t *ftp);
90 static int ftp_type(ftpbuf_t *ftp, ftptype_t type);
93 static databuf_t* ftp_getdata(ftpbuf_t *ftp);
96 static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp);
99 static databuf_t* data_close(ftpbuf_t *ftp, databuf_t *data);
102 static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, …
106 static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle);
121 ftpbuf_t *ftp; in ftp_open() local
127 ftp = ecalloc(1, sizeof(*ftp)); in ftp_open()
132 ftp->fd = php_network_connect_socket_to_host(host, in ftp_open()
135 if (ftp->fd == -1) { in ftp_open()
140 ftp->timeout_sec = timeout_sec; in ftp_open()
141 ftp->nb = 0; in ftp_open()
143 size = sizeof(ftp->localaddr); in ftp_open()
144 memset(&ftp->localaddr, 0, size); in ftp_open()
145 if (getsockname(ftp->fd, (struct sockaddr*) &ftp->localaddr, &size) != 0) { in ftp_open()
150 if (!ftp_getresp(ftp) || ftp->resp != 220) { in ftp_open()
154 return ftp; in ftp_open()
157 if (ftp->fd != -1) { in ftp_open()
158 closesocket(ftp->fd); in ftp_open()
160 efree(ftp); in ftp_open()
168 ftp_close(ftpbuf_t *ftp) in ftp_close() argument
170 if (ftp == NULL) { in ftp_close()
173 if (ftp->data) { in ftp_close()
174 data_close(ftp, ftp->data); in ftp_close()
176 if (ftp->stream && ftp->closestream) { in ftp_close()
177 php_stream_close(ftp->stream); in ftp_close()
179 if (ftp->fd != -1) { in ftp_close()
181 if (ftp->ssl_active) { in ftp_close()
182 ftp_ssl_shutdown(ftp, ftp->fd, ftp->ssl_handle); in ftp_close()
185 closesocket(ftp->fd); in ftp_close()
187 ftp_gc(ftp); in ftp_close()
188 efree(ftp); in ftp_close()
196 ftp_gc(ftpbuf_t *ftp) in ftp_gc() argument
198 if (ftp == NULL) { in ftp_gc()
201 if (ftp->pwd) { in ftp_gc()
202 efree(ftp->pwd); in ftp_gc()
203 ftp->pwd = NULL; in ftp_gc()
205 if (ftp->syst) { in ftp_gc()
206 efree(ftp->syst); in ftp_gc()
207 ftp->syst = NULL; in ftp_gc()
215 ftp_quit(ftpbuf_t *ftp) in ftp_quit() argument
217 if (ftp == NULL) { in ftp_quit()
221 if (!ftp_putcmd(ftp, "QUIT", sizeof("QUIT")-1, NULL, (size_t) 0)) { in ftp_quit()
224 if (!ftp_getresp(ftp) || ftp->resp != 221) { in ftp_quit()
228 if (ftp->pwd) { in ftp_quit()
229 efree(ftp->pwd); in ftp_quit()
230 ftp->pwd = NULL; in ftp_quit()
240 ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pa… in ftp_login() argument
248 if (ftp == NULL) { in ftp_login()
253 if (ftp->use_ssl && !ftp->ssl_active) { in ftp_login()
254 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "TLS", sizeof("TLS")-1)) { in ftp_login()
257 if (!ftp_getresp(ftp)) { in ftp_login()
261 if (ftp->resp != 234) { in ftp_login()
262 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "SSL", sizeof("SSL")-1)) { in ftp_login()
265 if (!ftp_getresp(ftp)) { in ftp_login()
269 if (ftp->resp != 334) { in ftp_login()
272 ftp->old_ssl = 1; in ftp_login()
273 ftp->use_ssl_for_data = 1; in ftp_login()
291 ftp->ssl_handle = SSL_new(ctx); in ftp_login()
294 if (ftp->ssl_handle == NULL) { in ftp_login()
299 SSL_set_fd(ftp->ssl_handle, ftp->fd); in ftp_login()
302 res = SSL_connect(ftp->ssl_handle); in ftp_login()
303 err = SSL_get_error(ftp->ssl_handle, res); in ftp_login()
313 SSL_shutdown(ftp->ssl_handle); in ftp_login()
321 p.fd = ftp->fd; in ftp_login()
333 SSL_shutdown(ftp->ssl_handle); in ftp_login()
334 SSL_free(ftp->ssl_handle); in ftp_login()
339 ftp->ssl_active = 1; in ftp_login()
341 if (!ftp->old_ssl) { in ftp_login()
344 if (!ftp_putcmd(ftp, "PBSZ", sizeof("PBSZ")-1, "0", sizeof("0")-1)) { in ftp_login()
347 if (!ftp_getresp(ftp)) { in ftp_login()
352 if (!ftp_putcmd(ftp, "PROT", sizeof("PROT")-1, "P", sizeof("P")-1)) { in ftp_login()
355 if (!ftp_getresp(ftp)) { in ftp_login()
359 ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp <=299); in ftp_login()
364 if (!ftp_putcmd(ftp, "USER", sizeof("USER")-1, user, user_len)) { in ftp_login()
367 if (!ftp_getresp(ftp)) { in ftp_login()
370 if (ftp->resp == 230) { in ftp_login()
373 if (ftp->resp != 331) { in ftp_login()
376 if (!ftp_putcmd(ftp, "PASS", sizeof("PASS")-1, pass, pass_len)) { in ftp_login()
379 if (!ftp_getresp(ftp)) { in ftp_login()
382 return (ftp->resp == 230); in ftp_login()
389 ftp_reinit(ftpbuf_t *ftp) in ftp_reinit() argument
391 if (ftp == NULL) { in ftp_reinit()
395 ftp_gc(ftp); in ftp_reinit()
397 ftp->nb = 0; in ftp_reinit()
399 if (!ftp_putcmd(ftp, "REIN", sizeof("REIN")-1, NULL, (size_t) 0)) { in ftp_reinit()
402 if (!ftp_getresp(ftp) || ftp->resp != 220) { in ftp_reinit()
413 ftp_syst(ftpbuf_t *ftp) in ftp_syst() argument
417 if (ftp == NULL) { in ftp_syst()
422 if (ftp->syst) { in ftp_syst()
423 return ftp->syst; in ftp_syst()
425 if (!ftp_putcmd(ftp, "SYST", sizeof("SYST")-1, NULL, (size_t) 0)) { in ftp_syst()
428 if (!ftp_getresp(ftp) || ftp->resp != 215) { in ftp_syst()
431 syst = ftp->inbuf; in ftp_syst()
438 ftp->syst = estrdup(syst); in ftp_syst()
442 return ftp->syst; in ftp_syst()
449 ftp_pwd(ftpbuf_t *ftp) in ftp_pwd() argument
453 if (ftp == NULL) { in ftp_pwd()
458 if (ftp->pwd) { in ftp_pwd()
459 return ftp->pwd; in ftp_pwd()
461 if (!ftp_putcmd(ftp, "PWD", sizeof("PWD")-1, NULL, (size_t) 0)) { in ftp_pwd()
464 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_pwd()
468 if ((pwd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_pwd()
474 ftp->pwd = estrndup(pwd, end - pwd); in ftp_pwd()
476 return ftp->pwd; in ftp_pwd()
483 ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_exec() argument
485 if (ftp == NULL) { in ftp_exec()
488 if (!ftp_putcmd(ftp, "SITE EXEC", sizeof("SITE EXEC")-1, cmd, cmd_len)) { in ftp_exec()
491 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_exec()
502 ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) in ftp_raw() argument
504 if (ftp == NULL || cmd == NULL) { in ftp_raw()
507 if (!ftp_putcmd(ftp, cmd, cmd_len, NULL, (size_t) 0)) { in ftp_raw()
511 while (ftp_readline(ftp)) { in ftp_raw()
512 add_next_index_string(return_value, ftp->inbuf); in ftp_raw()
513 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_raw()
523 ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_chdir() argument
525 if (ftp == NULL) { in ftp_chdir()
529 if (ftp->pwd) { in ftp_chdir()
530 efree(ftp->pwd); in ftp_chdir()
531 ftp->pwd = NULL; in ftp_chdir()
534 if (!ftp_putcmd(ftp, "CWD", sizeof("CWD")-1, dir, dir_len)) { in ftp_chdir()
537 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_chdir()
547 ftp_cdup(ftpbuf_t *ftp) in ftp_cdup() argument
549 if (ftp == NULL) { in ftp_cdup()
553 if (ftp->pwd) { in ftp_cdup()
554 efree(ftp->pwd); in ftp_cdup()
555 ftp->pwd = NULL; in ftp_cdup()
558 if (!ftp_putcmd(ftp, "CDUP", sizeof("CDUP")-1, NULL, (size_t) 0)) { in ftp_cdup()
561 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_cdup()
571 ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_mkdir() argument
576 if (ftp == NULL) { in ftp_mkdir()
579 if (!ftp_putcmd(ftp, "MKD", sizeof("MKD")-1, dir, dir_len)) { in ftp_mkdir()
582 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_mkdir()
586 if ((mkd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_mkdir()
603 ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_rmdir() argument
605 if (ftp == NULL) { in ftp_rmdir()
608 if (!ftp_putcmd(ftp, "RMD", sizeof("RMD")-1, dir, dir_len)) { in ftp_rmdir()
611 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rmdir()
621 ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len) in ftp_chmod() argument
626 if (ftp == NULL || filename_len <= 0) { in ftp_chmod()
636 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, buffer, buffer_len)) { in ftp_chmod()
643 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_chmod()
654 ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) in ftp_alloc() argument
659 if (ftp == NULL || size <= 0) { in ftp_alloc()
669 if (!ftp_putcmd(ftp, "ALLO", sizeof("ALLO")-1, buffer, buffer_len)) { in ftp_alloc()
673 if (!ftp_getresp(ftp)) { in ftp_alloc()
678 *response = zend_string_init(ftp->inbuf, strlen(ftp->inbuf), 0); in ftp_alloc()
681 if (ftp->resp < 200 || ftp->resp >= 300) { in ftp_alloc()
692 ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_nlist() argument
694 return ftp_genlist(ftp, "NLST", sizeof("NLST")-1, path, path_len); in ftp_nlist()
701 ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) in ftp_list() argument
703 …return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), ((recursive) ? sizeof("LIST -R")-1 : s… in ftp_list()
710 ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mlsd() argument
712 return ftp_genlist(ftp, "MLSD", sizeof("MLSD")-1, path, path_len); in ftp_mlsd()
764 ftp_type(ftpbuf_t *ftp, ftptype_t type) in ftp_type() argument
768 if (ftp == NULL) { in ftp_type()
771 if (type == ftp->type) { in ftp_type()
781 if (!ftp_putcmd(ftp, "TYPE", sizeof("TYPE")-1, typechar, 1)) { in ftp_type()
784 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_type()
787 ftp->type = type; in ftp_type()
796 ftp_pasv(ftpbuf_t *ftp, int pasv) in ftp_pasv() argument
805 if (ftp == NULL) { in ftp_pasv()
808 if (pasv && ftp->pasv == 2) { in ftp_pasv()
811 ftp->pasv = 0; in ftp_pasv()
815 n = sizeof(ftp->pasvaddr); in ftp_pasv()
816 memset(&ftp->pasvaddr, 0, n); in ftp_pasv()
817 sa = (struct sockaddr *) &ftp->pasvaddr; in ftp_pasv()
819 if (getpeername(ftp->fd, sa, &n) < 0) { in ftp_pasv()
829 if (!ftp_putcmd(ftp, "EPSV", sizeof("EPSV")-1, NULL, (size_t) 0)) { in ftp_pasv()
832 if (!ftp_getresp(ftp)) { in ftp_pasv()
835 if (ftp->resp == 229) { in ftp_pasv()
837 for (ptr = ftp->inbuf; *ptr && *ptr != '('; ptr++); in ftp_pasv()
852 ftp->pasv = 2; in ftp_pasv()
860 if (!ftp_putcmd(ftp, "PASV", sizeof("PASV")-1, NULL, (size_t) 0)) { in ftp_pasv()
863 if (!ftp_getresp(ftp) || ftp->resp != 227) { in ftp_pasv()
867 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_pasv()
876 if (ftp->usepasvaddress) { in ftp_pasv()
881 ftp->pasv = 2; in ftp_pasv()
890 ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t ty… in ftp_get() argument
896 if (ftp == NULL) { in ftp_get()
899 if (!ftp_type(ftp, type)) { in ftp_get()
903 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_get()
907 ftp->data = data; in ftp_get()
915 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_get()
918 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_get()
923 if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { in ftp_get()
926 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_get()
930 if ((data = data_accept(data, ftp)) == NULL) { in ftp_get()
934 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_get()
970 ftp->data = data = data_close(ftp, data); in ftp_get()
972 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_get()
978 ftp->data = data_close(ftp, data); in ftp_get()
986 ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t typ… in ftp_put() argument
994 if (ftp == NULL) { in ftp_put()
997 if (!ftp_type(ftp, type)) { in ftp_put()
1000 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_put()
1003 ftp->data = data; in ftp_put()
1011 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_put()
1014 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_put()
1019 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_put()
1022 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_put()
1025 if ((data = data_accept(data, ftp)) == NULL) { in ftp_put()
1034 if (my_send(ftp, data->fd, data->buf, size) != size) { in ftp_put()
1050 if (size && my_send(ftp, data->fd, data->buf, size) != size) { in ftp_put()
1053 ftp->data = data = data_close(ftp, data); in ftp_put()
1055 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_put()
1060 ftp->data = data_close(ftp, data); in ftp_put()
1069 ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_append() argument
1076 if (ftp == NULL) { in ftp_append()
1079 if (!ftp_type(ftp, type)) { in ftp_append()
1082 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_append()
1085 ftp->data = data; in ftp_append()
1087 if (!ftp_putcmd(ftp, "APPE", sizeof("APPE")-1, path, path_len)) { in ftp_append()
1090 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_append()
1093 if ((data = data_accept(data, ftp)) == NULL) { in ftp_append()
1102 if (my_send(ftp, data->fd, data->buf, size) != size) { in ftp_append()
1118 if (size && my_send(ftp, data->fd, data->buf, size) != size) { in ftp_append()
1121 ftp->data = data = data_close(ftp, data); in ftp_append()
1123 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_append()
1128 ftp->data = data_close(ftp, data); in ftp_append()
1136 ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_size() argument
1138 if (ftp == NULL) { in ftp_size()
1141 if (!ftp_type(ftp, FTPTYPE_IMAGE)) { in ftp_size()
1144 if (!ftp_putcmd(ftp, "SIZE", sizeof("SIZE")-1, path, path_len)) { in ftp_size()
1147 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_size()
1150 return atol(ftp->inbuf); in ftp_size()
1157 ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mdtm() argument
1165 if (ftp == NULL) { in ftp_mdtm()
1168 if (!ftp_putcmd(ftp, "MDTM", sizeof("MDTM")-1, path, path_len)) { in ftp_mdtm()
1171 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_mdtm()
1175 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_mdtm()
1205 ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_delete() argument
1207 if (ftp == NULL) { in ftp_delete()
1210 if (!ftp_putcmd(ftp, "DELE", sizeof("DELE")-1, path, path_len)) { in ftp_delete()
1213 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_delete()
1224 ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t des… in ftp_rename() argument
1226 if (ftp == NULL) { in ftp_rename()
1229 if (!ftp_putcmd(ftp, "RNFR", sizeof("RNFR")-1, src, src_len)) { in ftp_rename()
1232 if (!ftp_getresp(ftp) || ftp->resp != 350) { in ftp_rename()
1235 if (!ftp_putcmd(ftp, "RNTO", sizeof("RNTO")-1, dest, dest_len)) { in ftp_rename()
1238 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rename()
1248 ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_site() argument
1250 if (ftp == NULL) { in ftp_site()
1253 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, cmd, cmd_len)) { in ftp_site()
1256 if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) { in ftp_site()
1269 ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t arg… in ftp_putcmd() argument
1286 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args); in ftp_putcmd()
1292 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd); in ftp_putcmd()
1295 data = ftp->outbuf; in ftp_putcmd()
1298 ftp->extra = NULL; in ftp_putcmd()
1300 if (my_send(ftp, ftp->fd, data, size) != size) { in ftp_putcmd()
1310 ftp_readline(ftpbuf_t *ftp) in ftp_readline() argument
1318 if (ftp->extra) { in ftp_readline()
1319 memmove(ftp->inbuf, ftp->extra, ftp->extralen); in ftp_readline()
1320 rcvd = ftp->extralen; in ftp_readline()
1323 data = ftp->inbuf; in ftp_readline()
1330 ftp->extra = eol + 1; in ftp_readline()
1332 ftp->extra++; in ftp_readline()
1335 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1336 ftp->extra = NULL; in ftp_readline()
1341 ftp->extra = eol + 1; in ftp_readline()
1342 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1343 ftp->extra = NULL; in ftp_readline()
1350 if ((rcvd = my_recv(ftp, ftp->fd, data, size)) < 1) { in ftp_readline()
1362 ftp_getresp(ftpbuf_t *ftp) in ftp_getresp() argument
1364 if (ftp == NULL) { in ftp_getresp()
1367 ftp->resp = 0; in ftp_getresp()
1371 if (!ftp_readline(ftp)) { in ftp_getresp()
1376 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_getresp()
1382 if (!isdigit(ftp->inbuf[0]) || !isdigit(ftp->inbuf[1]) || !isdigit(ftp->inbuf[2])) { in ftp_getresp()
1386 ftp->resp = 100 * (ftp->inbuf[0] - '0') + 10 * (ftp->inbuf[1] - '0') + (ftp->inbuf[2] - '0'); in ftp_getresp()
1388 memmove(ftp->inbuf, ftp->inbuf + 4, FTP_BUFSIZE - 4); in ftp_getresp()
1390 if (ftp->extra) { in ftp_getresp()
1391 ftp->extra -= 4; in ftp_getresp()
1400 my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_send() argument
1414 n = php_pollfd_for_ms(s, POLLOUT, ftp->timeout_sec * 1000); in my_send()
1430 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in my_send()
1431 handle = ftp->ssl_handle; in my_send()
1432 fd = ftp->fd; in my_send()
1433 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in my_send()
1434 handle = ftp->data->ssl_handle; in my_send()
1435 fd = ftp->data->fd; in my_send()
1494 my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_recv() argument
1504 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_recv()
1519 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in my_recv()
1520 handle = ftp->ssl_handle; in my_recv()
1521 fd = ftp->fd; in my_recv()
1522 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in my_recv()
1523 handle = ftp->data->ssl_handle; in my_recv()
1524 fd = ftp->data->fd; in my_recv()
1575 data_available(ftpbuf_t *ftp, php_socket_t s) in data_available() argument
1599 data_writeable(ftpbuf_t *ftp, php_socket_t s) in data_writeable() argument
1624 my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen) in my_accept() argument
1628 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_accept()
1649 ftp_getdata(ftpbuf_t *ftp) in ftp_getdata() argument
1663 if (ftp->pasv && !ftp_pasv(ftp, 1)) { in ftp_getdata()
1670 data->type = ftp->type; in ftp_getdata()
1672 sa = (struct sockaddr *) &ftp->localaddr; in ftp_getdata()
1680 if (ftp->pasv) { in ftp_getdata()
1682 ftp->pasv = 1; in ftp_getdata()
1686 size = php_sockaddr_size(&ftp->pasvaddr); in ftp_getdata()
1687 tv.tv_sec = ftp->timeout_sec; in ftp_getdata()
1689 if (php_connect_nonb(fd, (struct sockaddr*) &ftp->pasvaddr, size, &tv) == -1) { in ftp_getdata()
1696 ftp->data = data; in ftp_getdata()
1737 if (!ftp_putcmd(ftp, "EPRT", sizeof("EPRT")-1, eprtarg, eprtarg_len)) { in ftp_getdata()
1741 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1745 ftp->data = data; in ftp_getdata()
1758 if (!ftp_putcmd(ftp, "PORT", sizeof("PORT")-1, arg, arg_len)) { in ftp_getdata()
1761 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1765 ftp->data = data; in ftp_getdata()
1780 data_accept(databuf_t *data, ftpbuf_t *ftp) in data_accept() argument
1796 data->fd = my_accept(ftp, data->listener, (struct sockaddr*) &addr, &size); in data_accept()
1809 if (ftp->use_ssl && ftp->use_ssl_for_data) { in data_accept()
1810 ctx = SSL_get_SSL_CTX(ftp->ssl_handle); in data_accept()
1824 if (ftp->old_ssl) { in data_accept()
1825 SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle); in data_accept()
1829 session = SSL_get_session(ftp->ssl_handle); in data_accept()
1893 static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { in ftp_ssl_shutdown() argument
1912 while (!done && data_available(ftp, fd)) { in ftp_ssl_shutdown()
1951 data_close(ftpbuf_t *ftp, databuf_t *data) in data_close() argument
1960 ftp_ssl_shutdown(ftp, data->listener, data->ssl_handle); in data_close()
1970 ftp_ssl_shutdown(ftp, data->fd, data->ssl_handle); in data_close()
1976 if (ftp) { in data_close()
1977 ftp->data = NULL; in data_close()
1987 ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t pa… in ftp_genlist() argument
2005 if (!ftp_type(ftp, FTPTYPE_ASCII)) { in ftp_genlist()
2009 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_genlist()
2012 ftp->data = data; in ftp_genlist()
2014 if (!ftp_putcmd(ftp, cmd, cmd_len, path, path_len)) { in ftp_genlist()
2017 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125 && ftp->resp != 226)) { in ftp_genlist()
2022 if (ftp->resp == 226) { in ftp_genlist()
2023 ftp->data = data_close(ftp, data); in ftp_genlist()
2029 if ((data = data_accept(data, ftp)) == NULL) { in ftp_genlist()
2035 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_genlist()
2051 ftp->data = data_close(ftp, data); in ftp_genlist()
2074 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_genlist()
2081 ftp->data = data_close(ftp, data); in ftp_genlist()
2092 ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t… in ftp_nb_get() argument
2097 if (ftp == NULL) { in ftp_nb_get()
2101 if (!ftp_type(ftp, type)) { in ftp_nb_get()
2105 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_get()
2115 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_get()
2118 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_get()
2123 if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { in ftp_nb_get()
2126 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_get()
2130 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_get()
2134 ftp->data = data; in ftp_nb_get()
2135 ftp->stream = outstream; in ftp_nb_get()
2136 ftp->lastch = 0; in ftp_nb_get()
2137 ftp->nb = 1; in ftp_nb_get()
2139 return (ftp_nb_continue_read(ftp)); in ftp_nb_get()
2142 ftp->data = data_close(ftp, data); in ftp_nb_get()
2150 ftp_nb_continue_read(ftpbuf_t *ftp) in ftp_nb_continue_read() argument
2158 data = ftp->data; in ftp_nb_continue_read()
2161 if (!data_available(ftp, data->fd)) { in ftp_nb_continue_read()
2165 type = ftp->type; in ftp_nb_continue_read()
2167 lastch = ftp->lastch; in ftp_nb_continue_read()
2168 if ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_nb_continue_read()
2176 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2179 php_stream_putc(ftp->stream, *ptr); in ftp_nb_continue_read()
2183 } else if (rcvd != php_stream_write(ftp->stream, data->buf, rcvd)) { in ftp_nb_continue_read()
2187 ftp->lastch = lastch; in ftp_nb_continue_read()
2192 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2195 ftp->data = data = data_close(ftp, data); in ftp_nb_continue_read()
2197 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_read()
2201 ftp->nb = 0; in ftp_nb_continue_read()
2204 ftp->nb = 0; in ftp_nb_continue_read()
2205 ftp->data = data_close(ftp, data); in ftp_nb_continue_read()
2213 ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_nb_put() argument
2218 if (ftp == NULL) { in ftp_nb_put()
2221 if (!ftp_type(ftp, type)) { in ftp_nb_put()
2224 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_put()
2233 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_put()
2236 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_put()
2241 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_nb_put()
2244 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_put()
2247 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_put()
2250 ftp->data = data; in ftp_nb_put()
2251 ftp->stream = instream; in ftp_nb_put()
2252 ftp->lastch = 0; in ftp_nb_put()
2253 ftp->nb = 1; in ftp_nb_put()
2255 return (ftp_nb_continue_write(ftp)); in ftp_nb_put()
2258 ftp->data = data_close(ftp, data); in ftp_nb_put()
2267 ftp_nb_continue_write(ftpbuf_t *ftp) in ftp_nb_continue_write() argument
2274 if (!data_writeable(ftp, ftp->data->fd)) { in ftp_nb_continue_write()
2279 ptr = ftp->data->buf; in ftp_nb_continue_write()
2280 while (!php_stream_eof(ftp->stream) && (ch = php_stream_getc(ftp->stream)) != EOF) { in ftp_nb_continue_write()
2282 if (ch == '\n' && ftp->type == FTPTYPE_ASCII) { in ftp_nb_continue_write()
2292 if (my_send(ftp, ftp->data->fd, ftp->data->buf, size) != size) { in ftp_nb_continue_write()
2299 if (size && my_send(ftp, ftp->data->fd, ftp->data->buf, size) != size) { in ftp_nb_continue_write()
2302 ftp->data = data_close(ftp, ftp->data); in ftp_nb_continue_write()
2304 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_write()
2307 ftp->nb = 0; in ftp_nb_continue_write()
2310 ftp->data = data_close(ftp, ftp->data); in ftp_nb_continue_write()
2311 ftp->nb = 0; in ftp_nb_continue_write()