Lines Matching refs:ftp
71 static int ftp_putcmd( ftpbuf_t *ftp,
78 static int my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len);
79 static int my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len);
80 static int my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen);
83 static int ftp_readline(ftpbuf_t *ftp);
86 static int ftp_getresp(ftpbuf_t *ftp);
89 static int ftp_type(ftpbuf_t *ftp, ftptype_t type);
92 static databuf_t* ftp_getdata(ftpbuf_t *ftp);
95 static databuf_t* data_accept(databuf_t *data, ftpbuf_t *ftp);
98 static databuf_t* data_close(ftpbuf_t *ftp, databuf_t *data);
101 static char** ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, …
105 static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle);
119 ftpbuf_t *ftp; in ftp_open() local
125 ftp = ecalloc(1, sizeof(*ftp)); in ftp_open()
130 ftp->fd = php_network_connect_socket_to_host(host, in ftp_open()
133 if (ftp->fd == -1) { in ftp_open()
138 ftp->timeout_sec = timeout_sec; in ftp_open()
139 ftp->nb = 0; in ftp_open()
141 size = sizeof(ftp->localaddr); in ftp_open()
142 memset(&ftp->localaddr, 0, size); in ftp_open()
143 if (getsockname(ftp->fd, (struct sockaddr*) &ftp->localaddr, &size) != 0) { in ftp_open()
148 if (!ftp_getresp(ftp) || ftp->resp != 220) { in ftp_open()
152 return ftp; in ftp_open()
155 if (ftp->fd != -1) { in ftp_open()
156 closesocket(ftp->fd); in ftp_open()
158 efree(ftp); in ftp_open()
165 ftp_close(ftpbuf_t *ftp) in ftp_close() argument
167 if (ftp == NULL) { in ftp_close()
171 if (ftp->last_ssl_session) { in ftp_close()
172 SSL_SESSION_free(ftp->last_ssl_session); in ftp_close()
175 if (ftp->data) { in ftp_close()
176 data_close(ftp, ftp->data); in ftp_close()
178 if (ftp->stream && ftp->closestream) { in ftp_close()
179 php_stream_close(ftp->stream); in ftp_close()
181 if (ftp->fd != -1) { in ftp_close()
183 if (ftp->ssl_active) { in ftp_close()
184 ftp_ssl_shutdown(ftp, ftp->fd, ftp->ssl_handle); in ftp_close()
187 closesocket(ftp->fd); in ftp_close()
189 ftp_gc(ftp); in ftp_close()
190 efree(ftp); in ftp_close()
197 ftp_gc(ftpbuf_t *ftp) in ftp_gc() argument
199 if (ftp == NULL) { in ftp_gc()
202 if (ftp->pwd) { in ftp_gc()
203 efree(ftp->pwd); in ftp_gc()
204 ftp->pwd = NULL; in ftp_gc()
206 if (ftp->syst) { in ftp_gc()
207 efree(ftp->syst); in ftp_gc()
208 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 ftpbuf_t *ftp = SSL_get_app_data(ssl); in ftp_ssl_new_session_cb() local
243 if (ftp->last_ssl_session) { in ftp_ssl_new_session_cb()
244 SSL_SESSION_free(ftp->last_ssl_session); in ftp_ssl_new_session_cb()
246 ftp->last_ssl_session = SSL_get1_session(ssl); in ftp_ssl_new_session_cb()
255 ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pa… in ftp_login() argument
263 if (ftp == NULL) { in ftp_login()
268 if (ftp->use_ssl && !ftp->ssl_active) { in ftp_login()
269 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "TLS", sizeof("TLS")-1)) { in ftp_login()
272 if (!ftp_getresp(ftp)) { in ftp_login()
276 if (ftp->resp != 234) { in ftp_login()
277 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "SSL", sizeof("SSL")-1)) { in ftp_login()
280 if (!ftp_getresp(ftp)) { in ftp_login()
284 if (ftp->resp != 334) { in ftp_login()
287 ftp->old_ssl = 1; in ftp_login()
288 ftp->use_ssl_for_data = 1; in ftp_login()
308 ftp->ssl_handle = SSL_new(ctx); in ftp_login()
309 SSL_set_app_data(ftp->ssl_handle, ftp); /* Needed for ftp_ssl_new_session_cb */ in ftp_login()
312 if (ftp->ssl_handle == NULL) { in ftp_login()
317 SSL_set_fd(ftp->ssl_handle, ftp->fd); in ftp_login()
320 res = SSL_connect(ftp->ssl_handle); in ftp_login()
321 err = SSL_get_error(ftp->ssl_handle, res); in ftp_login()
331 SSL_shutdown(ftp->ssl_handle); in ftp_login()
339 p.fd = ftp->fd; in ftp_login()
351 SSL_shutdown(ftp->ssl_handle); in ftp_login()
352 SSL_free(ftp->ssl_handle); in ftp_login()
357 ftp->ssl_active = 1; in ftp_login()
359 if (!ftp->old_ssl) { in ftp_login()
362 if (!ftp_putcmd(ftp, "PBSZ", sizeof("PBSZ")-1, "0", sizeof("0")-1)) { in ftp_login()
365 if (!ftp_getresp(ftp)) { in ftp_login()
370 if (!ftp_putcmd(ftp, "PROT", sizeof("PROT")-1, "P", sizeof("P")-1)) { in ftp_login()
373 if (!ftp_getresp(ftp)) { in ftp_login()
377 ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp <=299); in ftp_login()
382 if (!ftp_putcmd(ftp, "USER", sizeof("USER")-1, user, user_len)) { in ftp_login()
385 if (!ftp_getresp(ftp)) { in ftp_login()
388 if (ftp->resp == 230) { in ftp_login()
391 if (ftp->resp != 331) { in ftp_login()
394 if (!ftp_putcmd(ftp, "PASS", sizeof("PASS")-1, pass, pass_len)) { in ftp_login()
397 if (!ftp_getresp(ftp)) { in ftp_login()
400 return (ftp->resp == 230); in ftp_login()
406 ftp_reinit(ftpbuf_t *ftp) in ftp_reinit() argument
408 if (ftp == NULL) { in ftp_reinit()
412 ftp_gc(ftp); in ftp_reinit()
414 ftp->nb = 0; in ftp_reinit()
416 if (!ftp_putcmd(ftp, "REIN", sizeof("REIN")-1, NULL, (size_t) 0)) { in ftp_reinit()
419 if (!ftp_getresp(ftp) || ftp->resp != 220) { in ftp_reinit()
429 ftp_syst(ftpbuf_t *ftp) in ftp_syst() argument
433 if (ftp == NULL) { in ftp_syst()
438 if (ftp->syst) { in ftp_syst()
439 return ftp->syst; in ftp_syst()
441 if (!ftp_putcmd(ftp, "SYST", sizeof("SYST")-1, NULL, (size_t) 0)) { in ftp_syst()
444 if (!ftp_getresp(ftp) || ftp->resp != 215) { in ftp_syst()
447 syst = ftp->inbuf; in ftp_syst()
454 ftp->syst = estrdup(syst); in ftp_syst()
458 return ftp->syst; in ftp_syst()
464 ftp_pwd(ftpbuf_t *ftp) in ftp_pwd() argument
468 if (ftp == NULL) { in ftp_pwd()
473 if (ftp->pwd) { in ftp_pwd()
474 return ftp->pwd; in ftp_pwd()
476 if (!ftp_putcmd(ftp, "PWD", sizeof("PWD")-1, NULL, (size_t) 0)) { in ftp_pwd()
479 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_pwd()
483 if ((pwd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_pwd()
489 ftp->pwd = estrndup(pwd, end - pwd); in ftp_pwd()
491 return ftp->pwd; in ftp_pwd()
497 ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_exec() argument
499 if (ftp == NULL) { in ftp_exec()
502 if (!ftp_putcmd(ftp, "SITE EXEC", sizeof("SITE EXEC")-1, cmd, cmd_len)) { in ftp_exec()
505 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_exec()
515 ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) in ftp_raw() argument
517 if (ftp == NULL || cmd == NULL) { in ftp_raw()
520 if (!ftp_putcmd(ftp, cmd, cmd_len, NULL, (size_t) 0)) { in ftp_raw()
524 while (ftp_readline(ftp)) { in ftp_raw()
525 add_next_index_string(return_value, ftp->inbuf); in ftp_raw()
526 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_raw()
535 ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_chdir() argument
537 if (ftp == NULL) { in ftp_chdir()
541 if (ftp->pwd) { in ftp_chdir()
542 efree(ftp->pwd); in ftp_chdir()
543 ftp->pwd = NULL; in ftp_chdir()
546 if (!ftp_putcmd(ftp, "CWD", sizeof("CWD")-1, dir, dir_len)) { in ftp_chdir()
549 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_chdir()
558 ftp_cdup(ftpbuf_t *ftp) in ftp_cdup() argument
560 if (ftp == NULL) { in ftp_cdup()
564 if (ftp->pwd) { in ftp_cdup()
565 efree(ftp->pwd); in ftp_cdup()
566 ftp->pwd = NULL; in ftp_cdup()
569 if (!ftp_putcmd(ftp, "CDUP", sizeof("CDUP")-1, NULL, (size_t) 0)) { in ftp_cdup()
572 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_cdup()
581 ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_mkdir() argument
586 if (ftp == NULL) { in ftp_mkdir()
589 if (!ftp_putcmd(ftp, "MKD", sizeof("MKD")-1, dir, dir_len)) { in ftp_mkdir()
592 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_mkdir()
596 if ((mkd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_mkdir()
612 ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_rmdir() argument
614 if (ftp == NULL) { in ftp_rmdir()
617 if (!ftp_putcmd(ftp, "RMD", sizeof("RMD")-1, dir, dir_len)) { in ftp_rmdir()
620 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rmdir()
629 ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len) in ftp_chmod() argument
634 if (ftp == NULL || filename_len <= 0) { in ftp_chmod()
644 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, buffer, buffer_len)) { in ftp_chmod()
651 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_chmod()
661 ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) in ftp_alloc() argument
666 if (ftp == NULL || size <= 0) { in ftp_alloc()
676 if (!ftp_putcmd(ftp, "ALLO", sizeof("ALLO")-1, buffer, buffer_len)) { in ftp_alloc()
680 if (!ftp_getresp(ftp)) { in ftp_alloc()
685 *response = zend_string_init(ftp->inbuf, strlen(ftp->inbuf), 0); in ftp_alloc()
688 if (ftp->resp < 200 || ftp->resp >= 300) { in ftp_alloc()
698 ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_nlist() argument
700 return ftp_genlist(ftp, "NLST", sizeof("NLST")-1, path, path_len); in ftp_nlist()
706 ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) in ftp_list() argument
708 …return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), ((recursive) ? sizeof("LIST -R")-1 : s… in ftp_list()
714 ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mlsd() argument
716 return ftp_genlist(ftp, "MLSD", sizeof("MLSD")-1, path, path_len); in ftp_mlsd()
766 ftp_type(ftpbuf_t *ftp, ftptype_t type) in ftp_type() argument
770 if (ftp == NULL) { in ftp_type()
773 if (type == ftp->type) { in ftp_type()
783 if (!ftp_putcmd(ftp, "TYPE", sizeof("TYPE")-1, typechar, 1)) { in ftp_type()
786 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_type()
789 ftp->type = type; in ftp_type()
797 ftp_pasv(ftpbuf_t *ftp, int pasv) in ftp_pasv() argument
806 if (ftp == NULL) { in ftp_pasv()
809 if (pasv && ftp->pasv == 2) { in ftp_pasv()
812 ftp->pasv = 0; in ftp_pasv()
816 n = sizeof(ftp->pasvaddr); in ftp_pasv()
817 memset(&ftp->pasvaddr, 0, n); in ftp_pasv()
818 sa = (struct sockaddr *) &ftp->pasvaddr; in ftp_pasv()
820 if (getpeername(ftp->fd, sa, &n) < 0) { in ftp_pasv()
830 if (!ftp_putcmd(ftp, "EPSV", sizeof("EPSV")-1, NULL, (size_t) 0)) { in ftp_pasv()
833 if (!ftp_getresp(ftp)) { in ftp_pasv()
836 if (ftp->resp == 229) { in ftp_pasv()
838 for (ptr = ftp->inbuf; *ptr && *ptr != '('; ptr++); in ftp_pasv()
853 ftp->pasv = 2; in ftp_pasv()
861 if (!ftp_putcmd(ftp, "PASV", sizeof("PASV")-1, NULL, (size_t) 0)) { in ftp_pasv()
864 if (!ftp_getresp(ftp) || ftp->resp != 227) { in ftp_pasv()
868 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_pasv()
877 if (ftp->usepasvaddress) { in ftp_pasv()
882 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()
985 ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t typ… in ftp_put() argument
993 if (ftp == NULL) { in ftp_put()
996 if (!ftp_type(ftp, type)) { in ftp_put()
999 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_put()
1002 ftp->data = data; in ftp_put()
1010 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_put()
1013 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_put()
1018 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_put()
1021 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_put()
1024 if ((data = data_accept(data, ftp)) == NULL) { in ftp_put()
1033 if (my_send(ftp, data->fd, data->buf, size) != size) { in ftp_put()
1049 if (size && my_send(ftp, data->fd, data->buf, size) != size) { in ftp_put()
1052 ftp->data = data = data_close(ftp, data); in ftp_put()
1054 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_put()
1059 ftp->data = data_close(ftp, data); in ftp_put()
1067 ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_append() argument
1074 if (ftp == NULL) { in ftp_append()
1077 if (!ftp_type(ftp, type)) { in ftp_append()
1080 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_append()
1083 ftp->data = data; in ftp_append()
1085 if (!ftp_putcmd(ftp, "APPE", sizeof("APPE")-1, path, path_len)) { in ftp_append()
1088 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_append()
1091 if ((data = data_accept(data, ftp)) == NULL) { in ftp_append()
1100 if (my_send(ftp, data->fd, data->buf, size) != size) { in ftp_append()
1116 if (size && my_send(ftp, data->fd, data->buf, size) != size) { in ftp_append()
1119 ftp->data = data = data_close(ftp, data); in ftp_append()
1121 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_append()
1126 ftp->data = data_close(ftp, data); in ftp_append()
1133 ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_size() argument
1135 if (ftp == NULL) { in ftp_size()
1138 if (!ftp_type(ftp, FTPTYPE_IMAGE)) { in ftp_size()
1141 if (!ftp_putcmd(ftp, "SIZE", sizeof("SIZE")-1, path, path_len)) { in ftp_size()
1144 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_size()
1147 return ZEND_ATOL(ftp->inbuf); in ftp_size()
1153 ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mdtm() argument
1161 if (ftp == NULL) { in ftp_mdtm()
1164 if (!ftp_putcmd(ftp, "MDTM", sizeof("MDTM")-1, path, path_len)) { in ftp_mdtm()
1167 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_mdtm()
1171 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_mdtm()
1200 ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_delete() argument
1202 if (ftp == NULL) { in ftp_delete()
1205 if (!ftp_putcmd(ftp, "DELE", sizeof("DELE")-1, path, path_len)) { in ftp_delete()
1208 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_delete()
1218 ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t des… in ftp_rename() argument
1220 if (ftp == NULL) { in ftp_rename()
1223 if (!ftp_putcmd(ftp, "RNFR", sizeof("RNFR")-1, src, src_len)) { in ftp_rename()
1226 if (!ftp_getresp(ftp) || ftp->resp != 350) { in ftp_rename()
1229 if (!ftp_putcmd(ftp, "RNTO", sizeof("RNTO")-1, dest, dest_len)) { in ftp_rename()
1232 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rename()
1241 ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_site() argument
1243 if (ftp == NULL) { in ftp_site()
1246 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, cmd, cmd_len)) { in ftp_site()
1249 if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) { in ftp_site()
1261 ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t arg… in ftp_putcmd() argument
1278 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args); in ftp_putcmd()
1284 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd); in ftp_putcmd()
1287 data = ftp->outbuf; in ftp_putcmd()
1290 ftp->inbuf[0] = '\0'; in ftp_putcmd()
1291 ftp->extra = NULL; in ftp_putcmd()
1293 if (my_send(ftp, ftp->fd, data, size) != size) { in ftp_putcmd()
1302 ftp_readline(ftpbuf_t *ftp) in ftp_readline() argument
1310 if (ftp->extra) { in ftp_readline()
1311 memmove(ftp->inbuf, ftp->extra, ftp->extralen); in ftp_readline()
1312 rcvd = ftp->extralen; in ftp_readline()
1315 data = ftp->inbuf; in ftp_readline()
1322 ftp->extra = eol + 1; in ftp_readline()
1324 ftp->extra++; in ftp_readline()
1327 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1328 ftp->extra = NULL; in ftp_readline()
1333 ftp->extra = eol + 1; in ftp_readline()
1334 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1335 ftp->extra = NULL; in ftp_readline()
1342 if ((rcvd = my_recv(ftp, ftp->fd, data, size)) < 1) { in ftp_readline()
1355 ftp_getresp(ftpbuf_t *ftp) in ftp_getresp() argument
1357 if (ftp == NULL) { in ftp_getresp()
1360 ftp->resp = 0; in ftp_getresp()
1364 if (!ftp_readline(ftp)) { in ftp_getresp()
1369 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_getresp()
1375 if (!isdigit(ftp->inbuf[0]) || !isdigit(ftp->inbuf[1]) || !isdigit(ftp->inbuf[2])) { in ftp_getresp()
1379 ftp->resp = 100 * (ftp->inbuf[0] - '0') + 10 * (ftp->inbuf[1] - '0') + (ftp->inbuf[2] - '0'); in ftp_getresp()
1381 memmove(ftp->inbuf, ftp->inbuf + 4, FTP_BUFSIZE - 4); in ftp_getresp()
1383 if (ftp->extra) { in ftp_getresp()
1384 ftp->extra -= 4; in ftp_getresp()
1390 int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { in single_send() argument
1398 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in single_send()
1399 handle = ftp->ssl_handle; in single_send()
1400 fd = ftp->fd; in single_send()
1401 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in single_send()
1402 handle = ftp->data->ssl_handle; in single_send()
1403 fd = ftp->data->fd; in single_send()
1450 my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_send() argument
1457 n = php_pollfd_for_ms(s, POLLOUT, ftp->timeout_sec * 1000); in my_send()
1472 sent = single_send(ftp, s, buf, size); in my_send()
1487 my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_recv() argument
1496 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_recv()
1511 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in my_recv()
1512 handle = ftp->ssl_handle; in my_recv()
1513 fd = ftp->fd; in my_recv()
1514 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in my_recv()
1515 handle = ftp->data->ssl_handle; in my_recv()
1516 fd = ftp->data->fd; in my_recv()
1566 data_available(ftpbuf_t *ftp, php_socket_t s) in data_available() argument
1589 data_writeable(ftpbuf_t *ftp, php_socket_t s) in data_writeable() argument
1613 my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen) in my_accept() argument
1617 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_accept()
1637 ftp_getdata(ftpbuf_t *ftp) in ftp_getdata() argument
1651 if (ftp->pasv && !ftp_pasv(ftp, 1)) { in ftp_getdata()
1658 data->type = ftp->type; in ftp_getdata()
1660 sa = (struct sockaddr *) &ftp->localaddr; in ftp_getdata()
1668 if (ftp->pasv) { in ftp_getdata()
1670 ftp->pasv = 1; in ftp_getdata()
1674 size = php_sockaddr_size(&ftp->pasvaddr); in ftp_getdata()
1675 tv.tv_sec = ftp->timeout_sec; in ftp_getdata()
1677 if (php_connect_nonb(fd, (struct sockaddr*) &ftp->pasvaddr, size, &tv) == -1) { in ftp_getdata()
1684 ftp->data = data; in ftp_getdata()
1725 if (!ftp_putcmd(ftp, "EPRT", sizeof("EPRT")-1, eprtarg, eprtarg_len)) { in ftp_getdata()
1729 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1733 ftp->data = data; in ftp_getdata()
1746 if (!ftp_putcmd(ftp, "PORT", sizeof("PORT")-1, arg, arg_len)) { in ftp_getdata()
1749 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1753 ftp->data = data; in ftp_getdata()
1767 data_accept(databuf_t *data, ftpbuf_t *ftp) in data_accept() argument
1783 data->fd = my_accept(ftp, data->listener, (struct sockaddr*) &addr, &size); in data_accept()
1796 if (ftp->use_ssl && ftp->use_ssl_for_data) { in data_accept()
1797 ctx = SSL_get_SSL_CTX(ftp->ssl_handle); in data_accept()
1811 if (ftp->old_ssl) { in data_accept()
1812 SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle); in data_accept()
1816 session = ftp->last_ssl_session; in data_accept()
1824 SSL_set_app_data(data->ssl_handle, ftp); /* Needed for ftp_ssl_new_session_cb */ in data_accept()
1880 static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { in ftp_ssl_shutdown() argument
1899 while (!done && data_available(ftp, fd)) { in ftp_ssl_shutdown()
1943 data_close(ftpbuf_t *ftp, databuf_t *data) in data_close() argument
1952 ftp_ssl_shutdown(ftp, data->listener, data->ssl_handle); in data_close()
1962 ftp_ssl_shutdown(ftp, data->fd, data->ssl_handle); in data_close()
1968 if (ftp) { in data_close()
1969 ftp->data = NULL; in data_close()
1978 ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t pa… in ftp_genlist() argument
1996 if (!ftp_type(ftp, FTPTYPE_ASCII)) { in ftp_genlist()
2000 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_genlist()
2003 ftp->data = data; in ftp_genlist()
2005 if (!ftp_putcmd(ftp, cmd, cmd_len, path, path_len)) { in ftp_genlist()
2008 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125 && ftp->resp != 226)) { in ftp_genlist()
2013 if (ftp->resp == 226) { in ftp_genlist()
2014 ftp->data = data_close(ftp, data); in ftp_genlist()
2020 if ((data = data_accept(data, ftp)) == NULL) { in ftp_genlist()
2026 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_genlist()
2042 ftp->data = data_close(ftp, data); in ftp_genlist()
2065 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_genlist()
2072 ftp->data = data_close(ftp, data); in ftp_genlist()
2082 ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t… in ftp_nb_get() argument
2087 if (ftp == NULL) { in ftp_nb_get()
2091 if (ftp->data != NULL) { in ftp_nb_get()
2094 data_close(ftp, ftp->data); in ftp_nb_get()
2095 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_get()
2100 if (!ftp_type(ftp, type)) { in ftp_nb_get()
2104 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_get()
2114 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_get()
2117 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_get()
2122 if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { in ftp_nb_get()
2125 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_get()
2129 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_get()
2133 ftp->data = data; in ftp_nb_get()
2134 ftp->stream = outstream; in ftp_nb_get()
2135 ftp->lastch = 0; in ftp_nb_get()
2136 ftp->nb = 1; in ftp_nb_get()
2138 return (ftp_nb_continue_read(ftp)); in ftp_nb_get()
2141 ftp->data = data_close(ftp, data); in ftp_nb_get()
2148 ftp_nb_continue_read(ftpbuf_t *ftp) in ftp_nb_continue_read() argument
2156 data = ftp->data; in ftp_nb_continue_read()
2159 if (!data_available(ftp, data->fd)) { in ftp_nb_continue_read()
2163 type = ftp->type; in ftp_nb_continue_read()
2165 lastch = ftp->lastch; in ftp_nb_continue_read()
2166 if ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_nb_continue_read()
2174 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2177 php_stream_putc(ftp->stream, *ptr); in ftp_nb_continue_read()
2181 } else if (rcvd != php_stream_write(ftp->stream, data->buf, rcvd)) { in ftp_nb_continue_read()
2185 ftp->lastch = lastch; in ftp_nb_continue_read()
2190 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2193 ftp->data = data = data_close(ftp, data); in ftp_nb_continue_read()
2195 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_read()
2199 ftp->nb = 0; in ftp_nb_continue_read()
2202 ftp->nb = 0; in ftp_nb_continue_read()
2203 ftp->data = data_close(ftp, data); in ftp_nb_continue_read()
2210 ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_nb_put() argument
2215 if (ftp == NULL) { in ftp_nb_put()
2218 if (!ftp_type(ftp, type)) { in ftp_nb_put()
2221 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_put()
2230 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_put()
2233 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_put()
2238 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_nb_put()
2241 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_put()
2244 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_put()
2247 ftp->data = data; in ftp_nb_put()
2248 ftp->stream = instream; in ftp_nb_put()
2249 ftp->lastch = 0; in ftp_nb_put()
2250 ftp->nb = 1; in ftp_nb_put()
2252 return (ftp_nb_continue_write(ftp)); in ftp_nb_put()
2255 ftp->data = data_close(ftp, data); in ftp_nb_put()
2263 ftp_nb_continue_write(ftpbuf_t *ftp) in ftp_nb_continue_write() argument
2270 if (!data_writeable(ftp, ftp->data->fd)) { in ftp_nb_continue_write()
2275 ptr = ftp->data->buf; in ftp_nb_continue_write()
2276 while (!php_stream_eof(ftp->stream) && (ch = php_stream_getc(ftp->stream)) != EOF) { in ftp_nb_continue_write()
2278 if (ch == '\n' && ftp->type == FTPTYPE_ASCII) { in ftp_nb_continue_write()
2288 if (my_send(ftp, ftp->data->fd, ftp->data->buf, size) != size) { in ftp_nb_continue_write()
2295 if (size && my_send(ftp, ftp->data->fd, ftp->data->buf, size) != size) { in ftp_nb_continue_write()
2298 ftp->data = data_close(ftp, ftp->data); in ftp_nb_continue_write()
2300 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_write()
2303 ftp->nb = 0; in ftp_nb_continue_write()
2306 ftp->data = data_close(ftp, ftp->data); in ftp_nb_continue_write()
2307 ftp->nb = 0; in ftp_nb_continue_write()