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()
170 if (ftp->data) { in ftp_close()
171 data_close(ftp, ftp->data); in ftp_close()
173 if (ftp->stream && ftp->closestream) { in ftp_close()
174 php_stream_close(ftp->stream); in ftp_close()
176 if (ftp->fd != -1) { in ftp_close()
178 if (ftp->ssl_active) { in ftp_close()
179 ftp_ssl_shutdown(ftp, ftp->fd, ftp->ssl_handle); in ftp_close()
182 closesocket(ftp->fd); in ftp_close()
184 ftp_gc(ftp); in ftp_close()
185 efree(ftp); in ftp_close()
192 ftp_gc(ftpbuf_t *ftp) in ftp_gc() argument
194 if (ftp == NULL) { in ftp_gc()
197 if (ftp->pwd) { in ftp_gc()
198 efree(ftp->pwd); in ftp_gc()
199 ftp->pwd = NULL; in ftp_gc()
201 if (ftp->syst) { in ftp_gc()
202 efree(ftp->syst); in ftp_gc()
203 ftp->syst = NULL; in ftp_gc()
210 ftp_quit(ftpbuf_t *ftp) in ftp_quit() argument
212 if (ftp == NULL) { in ftp_quit()
216 if (!ftp_putcmd(ftp, "QUIT", sizeof("QUIT")-1, NULL, (size_t) 0)) { in ftp_quit()
219 if (!ftp_getresp(ftp) || ftp->resp != 221) { in ftp_quit()
223 if (ftp->pwd) { in ftp_quit()
224 efree(ftp->pwd); in ftp_quit()
225 ftp->pwd = NULL; in ftp_quit()
234 ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pa… in ftp_login() argument
242 if (ftp == NULL) { in ftp_login()
247 if (ftp->use_ssl && !ftp->ssl_active) { in ftp_login()
248 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "TLS", sizeof("TLS")-1)) { in ftp_login()
251 if (!ftp_getresp(ftp)) { in ftp_login()
255 if (ftp->resp != 234) { in ftp_login()
256 if (!ftp_putcmd(ftp, "AUTH", sizeof("AUTH")-1, "SSL", sizeof("SSL")-1)) { in ftp_login()
259 if (!ftp_getresp(ftp)) { in ftp_login()
263 if (ftp->resp != 334) { in ftp_login()
266 ftp->old_ssl = 1; in ftp_login()
267 ftp->use_ssl_for_data = 1; in ftp_login()
285 ftp->ssl_handle = SSL_new(ctx); in ftp_login()
288 if (ftp->ssl_handle == NULL) { in ftp_login()
293 SSL_set_fd(ftp->ssl_handle, ftp->fd); in ftp_login()
296 res = SSL_connect(ftp->ssl_handle); in ftp_login()
297 err = SSL_get_error(ftp->ssl_handle, res); in ftp_login()
307 SSL_shutdown(ftp->ssl_handle); in ftp_login()
315 p.fd = ftp->fd; in ftp_login()
327 SSL_shutdown(ftp->ssl_handle); in ftp_login()
328 SSL_free(ftp->ssl_handle); in ftp_login()
333 ftp->ssl_active = 1; in ftp_login()
335 if (!ftp->old_ssl) { in ftp_login()
338 if (!ftp_putcmd(ftp, "PBSZ", sizeof("PBSZ")-1, "0", sizeof("0")-1)) { in ftp_login()
341 if (!ftp_getresp(ftp)) { in ftp_login()
346 if (!ftp_putcmd(ftp, "PROT", sizeof("PROT")-1, "P", sizeof("P")-1)) { in ftp_login()
349 if (!ftp_getresp(ftp)) { in ftp_login()
353 ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp <=299); in ftp_login()
358 if (!ftp_putcmd(ftp, "USER", sizeof("USER")-1, user, user_len)) { in ftp_login()
361 if (!ftp_getresp(ftp)) { in ftp_login()
364 if (ftp->resp == 230) { in ftp_login()
367 if (ftp->resp != 331) { in ftp_login()
370 if (!ftp_putcmd(ftp, "PASS", sizeof("PASS")-1, pass, pass_len)) { in ftp_login()
373 if (!ftp_getresp(ftp)) { in ftp_login()
376 return (ftp->resp == 230); in ftp_login()
382 ftp_reinit(ftpbuf_t *ftp) in ftp_reinit() argument
384 if (ftp == NULL) { in ftp_reinit()
388 ftp_gc(ftp); in ftp_reinit()
390 ftp->nb = 0; in ftp_reinit()
392 if (!ftp_putcmd(ftp, "REIN", sizeof("REIN")-1, NULL, (size_t) 0)) { in ftp_reinit()
395 if (!ftp_getresp(ftp) || ftp->resp != 220) { in ftp_reinit()
405 ftp_syst(ftpbuf_t *ftp) in ftp_syst() argument
409 if (ftp == NULL) { in ftp_syst()
414 if (ftp->syst) { in ftp_syst()
415 return ftp->syst; in ftp_syst()
417 if (!ftp_putcmd(ftp, "SYST", sizeof("SYST")-1, NULL, (size_t) 0)) { in ftp_syst()
420 if (!ftp_getresp(ftp) || ftp->resp != 215) { in ftp_syst()
423 syst = ftp->inbuf; in ftp_syst()
430 ftp->syst = estrdup(syst); in ftp_syst()
434 return ftp->syst; in ftp_syst()
440 ftp_pwd(ftpbuf_t *ftp) in ftp_pwd() argument
444 if (ftp == NULL) { in ftp_pwd()
449 if (ftp->pwd) { in ftp_pwd()
450 return ftp->pwd; in ftp_pwd()
452 if (!ftp_putcmd(ftp, "PWD", sizeof("PWD")-1, NULL, (size_t) 0)) { in ftp_pwd()
455 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_pwd()
459 if ((pwd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_pwd()
465 ftp->pwd = estrndup(pwd, end - pwd); in ftp_pwd()
467 return ftp->pwd; in ftp_pwd()
473 ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_exec() argument
475 if (ftp == NULL) { in ftp_exec()
478 if (!ftp_putcmd(ftp, "SITE EXEC", sizeof("SITE EXEC")-1, cmd, cmd_len)) { in ftp_exec()
481 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_exec()
491 ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value) in ftp_raw() argument
493 if (ftp == NULL || cmd == NULL) { in ftp_raw()
496 if (!ftp_putcmd(ftp, cmd, cmd_len, NULL, (size_t) 0)) { in ftp_raw()
500 while (ftp_readline(ftp)) { in ftp_raw()
501 add_next_index_string(return_value, ftp->inbuf); in ftp_raw()
502 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_raw()
511 ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_chdir() argument
513 if (ftp == NULL) { in ftp_chdir()
517 if (ftp->pwd) { in ftp_chdir()
518 efree(ftp->pwd); in ftp_chdir()
519 ftp->pwd = NULL; in ftp_chdir()
522 if (!ftp_putcmd(ftp, "CWD", sizeof("CWD")-1, dir, dir_len)) { in ftp_chdir()
525 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_chdir()
534 ftp_cdup(ftpbuf_t *ftp) in ftp_cdup() argument
536 if (ftp == NULL) { in ftp_cdup()
540 if (ftp->pwd) { in ftp_cdup()
541 efree(ftp->pwd); in ftp_cdup()
542 ftp->pwd = NULL; in ftp_cdup()
545 if (!ftp_putcmd(ftp, "CDUP", sizeof("CDUP")-1, NULL, (size_t) 0)) { in ftp_cdup()
548 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_cdup()
557 ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_mkdir() argument
562 if (ftp == NULL) { in ftp_mkdir()
565 if (!ftp_putcmd(ftp, "MKD", sizeof("MKD")-1, dir, dir_len)) { in ftp_mkdir()
568 if (!ftp_getresp(ftp) || ftp->resp != 257) { in ftp_mkdir()
572 if ((mkd = strchr(ftp->inbuf, '"')) == NULL) { in ftp_mkdir()
588 ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len) in ftp_rmdir() argument
590 if (ftp == NULL) { in ftp_rmdir()
593 if (!ftp_putcmd(ftp, "RMD", sizeof("RMD")-1, dir, dir_len)) { in ftp_rmdir()
596 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rmdir()
605 ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len) in ftp_chmod() argument
610 if (ftp == NULL || filename_len <= 0) { in ftp_chmod()
620 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, buffer, buffer_len)) { in ftp_chmod()
627 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_chmod()
637 ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response) in ftp_alloc() argument
642 if (ftp == NULL || size <= 0) { in ftp_alloc()
652 if (!ftp_putcmd(ftp, "ALLO", sizeof("ALLO")-1, buffer, buffer_len)) { in ftp_alloc()
656 if (!ftp_getresp(ftp)) { in ftp_alloc()
661 *response = zend_string_init(ftp->inbuf, strlen(ftp->inbuf), 0); in ftp_alloc()
664 if (ftp->resp < 200 || ftp->resp >= 300) { in ftp_alloc()
674 ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_nlist() argument
676 return ftp_genlist(ftp, "NLST", sizeof("NLST")-1, path, path_len); in ftp_nlist()
682 ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive) in ftp_list() argument
684 …return ftp_genlist(ftp, ((recursive) ? "LIST -R" : "LIST"), ((recursive) ? sizeof("LIST -R")-1 : s… in ftp_list()
690 ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mlsd() argument
692 return ftp_genlist(ftp, "MLSD", sizeof("MLSD")-1, path, path_len); in ftp_mlsd()
742 ftp_type(ftpbuf_t *ftp, ftptype_t type) in ftp_type() argument
746 if (ftp == NULL) { in ftp_type()
749 if (type == ftp->type) { in ftp_type()
759 if (!ftp_putcmd(ftp, "TYPE", sizeof("TYPE")-1, typechar, 1)) { in ftp_type()
762 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_type()
765 ftp->type = type; in ftp_type()
773 ftp_pasv(ftpbuf_t *ftp, int pasv) in ftp_pasv() argument
782 if (ftp == NULL) { in ftp_pasv()
785 if (pasv && ftp->pasv == 2) { in ftp_pasv()
788 ftp->pasv = 0; in ftp_pasv()
792 n = sizeof(ftp->pasvaddr); in ftp_pasv()
793 memset(&ftp->pasvaddr, 0, n); in ftp_pasv()
794 sa = (struct sockaddr *) &ftp->pasvaddr; in ftp_pasv()
796 if (getpeername(ftp->fd, sa, &n) < 0) { in ftp_pasv()
806 if (!ftp_putcmd(ftp, "EPSV", sizeof("EPSV")-1, NULL, (size_t) 0)) { in ftp_pasv()
809 if (!ftp_getresp(ftp)) { in ftp_pasv()
812 if (ftp->resp == 229) { in ftp_pasv()
814 for (ptr = ftp->inbuf; *ptr && *ptr != '('; ptr++); in ftp_pasv()
829 ftp->pasv = 2; in ftp_pasv()
837 if (!ftp_putcmd(ftp, "PASV", sizeof("PASV")-1, NULL, (size_t) 0)) { in ftp_pasv()
840 if (!ftp_getresp(ftp) || ftp->resp != 227) { in ftp_pasv()
844 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_pasv()
853 if (ftp->usepasvaddress) { in ftp_pasv()
858 ftp->pasv = 2; in ftp_pasv()
866 ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t ty… in ftp_get() argument
872 if (ftp == NULL) { in ftp_get()
875 if (!ftp_type(ftp, type)) { in ftp_get()
879 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_get()
883 ftp->data = data; in ftp_get()
891 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_get()
894 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_get()
899 if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { in ftp_get()
902 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_get()
906 if ((data = data_accept(data, ftp)) == NULL) { in ftp_get()
910 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_get()
946 ftp->data = data = data_close(ftp, data); in ftp_get()
948 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_get()
954 ftp->data = data_close(ftp, data); in ftp_get()
961 ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t typ… in ftp_put() argument
969 if (ftp == NULL) { in ftp_put()
972 if (!ftp_type(ftp, type)) { in ftp_put()
975 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_put()
978 ftp->data = data; in ftp_put()
986 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_put()
989 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_put()
994 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_put()
997 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_put()
1000 if ((data = data_accept(data, ftp)) == NULL) { in ftp_put()
1009 if (my_send(ftp, data->fd, data->buf, size) != size) { in ftp_put()
1025 if (size && my_send(ftp, data->fd, data->buf, size) != size) { in ftp_put()
1028 ftp->data = data = data_close(ftp, data); in ftp_put()
1030 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_put()
1035 ftp->data = data_close(ftp, data); in ftp_put()
1043 ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_append() argument
1050 if (ftp == NULL) { in ftp_append()
1053 if (!ftp_type(ftp, type)) { in ftp_append()
1056 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_append()
1059 ftp->data = data; in ftp_append()
1061 if (!ftp_putcmd(ftp, "APPE", sizeof("APPE")-1, path, path_len)) { in ftp_append()
1064 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_append()
1067 if ((data = data_accept(data, ftp)) == NULL) { in ftp_append()
1076 if (my_send(ftp, data->fd, data->buf, size) != size) { in ftp_append()
1092 if (size && my_send(ftp, data->fd, data->buf, size) != size) { in ftp_append()
1095 ftp->data = data = data_close(ftp, data); in ftp_append()
1097 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250 && ftp->resp != 200)) { in ftp_append()
1102 ftp->data = data_close(ftp, data); in ftp_append()
1109 ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_size() argument
1111 if (ftp == NULL) { in ftp_size()
1114 if (!ftp_type(ftp, FTPTYPE_IMAGE)) { in ftp_size()
1117 if (!ftp_putcmd(ftp, "SIZE", sizeof("SIZE")-1, path, path_len)) { in ftp_size()
1120 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_size()
1123 return ZEND_ATOL(ftp->inbuf); in ftp_size()
1129 ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_mdtm() argument
1137 if (ftp == NULL) { in ftp_mdtm()
1140 if (!ftp_putcmd(ftp, "MDTM", sizeof("MDTM")-1, path, path_len)) { in ftp_mdtm()
1143 if (!ftp_getresp(ftp) || ftp->resp != 213) { in ftp_mdtm()
1147 for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++); in ftp_mdtm()
1176 ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len) in ftp_delete() argument
1178 if (ftp == NULL) { in ftp_delete()
1181 if (!ftp_putcmd(ftp, "DELE", sizeof("DELE")-1, path, path_len)) { in ftp_delete()
1184 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_delete()
1194 ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t des… in ftp_rename() argument
1196 if (ftp == NULL) { in ftp_rename()
1199 if (!ftp_putcmd(ftp, "RNFR", sizeof("RNFR")-1, src, src_len)) { in ftp_rename()
1202 if (!ftp_getresp(ftp) || ftp->resp != 350) { in ftp_rename()
1205 if (!ftp_putcmd(ftp, "RNTO", sizeof("RNTO")-1, dest, dest_len)) { in ftp_rename()
1208 if (!ftp_getresp(ftp) || ftp->resp != 250) { in ftp_rename()
1217 ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len) in ftp_site() argument
1219 if (ftp == NULL) { in ftp_site()
1222 if (!ftp_putcmd(ftp, "SITE", sizeof("SITE")-1, cmd, cmd_len)) { in ftp_site()
1225 if (!ftp_getresp(ftp) || ftp->resp < 200 || ftp->resp >= 300) { in ftp_site()
1237 ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *args, const size_t arg… in ftp_putcmd() argument
1254 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args); in ftp_putcmd()
1260 size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd); in ftp_putcmd()
1263 data = ftp->outbuf; in ftp_putcmd()
1266 ftp->inbuf[0] = '\0'; in ftp_putcmd()
1267 ftp->extra = NULL; in ftp_putcmd()
1269 if (my_send(ftp, ftp->fd, data, size) != size) { in ftp_putcmd()
1278 ftp_readline(ftpbuf_t *ftp) in ftp_readline() argument
1286 if (ftp->extra) { in ftp_readline()
1287 memmove(ftp->inbuf, ftp->extra, ftp->extralen); in ftp_readline()
1288 rcvd = ftp->extralen; in ftp_readline()
1291 data = ftp->inbuf; in ftp_readline()
1298 ftp->extra = eol + 1; in ftp_readline()
1300 ftp->extra++; in ftp_readline()
1303 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1304 ftp->extra = NULL; in ftp_readline()
1309 ftp->extra = eol + 1; in ftp_readline()
1310 if ((ftp->extralen = --rcvd) == 0) { in ftp_readline()
1311 ftp->extra = NULL; in ftp_readline()
1318 if ((rcvd = my_recv(ftp, ftp->fd, data, size)) < 1) { in ftp_readline()
1331 ftp_getresp(ftpbuf_t *ftp) in ftp_getresp() argument
1333 if (ftp == NULL) { in ftp_getresp()
1336 ftp->resp = 0; in ftp_getresp()
1340 if (!ftp_readline(ftp)) { in ftp_getresp()
1345 …if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] ==… in ftp_getresp()
1351 if (!isdigit(ftp->inbuf[0]) || !isdigit(ftp->inbuf[1]) || !isdigit(ftp->inbuf[2])) { in ftp_getresp()
1355 ftp->resp = 100 * (ftp->inbuf[0] - '0') + 10 * (ftp->inbuf[1] - '0') + (ftp->inbuf[2] - '0'); in ftp_getresp()
1357 memmove(ftp->inbuf, ftp->inbuf + 4, FTP_BUFSIZE - 4); in ftp_getresp()
1359 if (ftp->extra) { in ftp_getresp()
1360 ftp->extra -= 4; in ftp_getresp()
1366 int single_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t size) { in single_send() argument
1374 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in single_send()
1375 handle = ftp->ssl_handle; in single_send()
1376 fd = ftp->fd; in single_send()
1377 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in single_send()
1378 handle = ftp->data->ssl_handle; in single_send()
1379 fd = ftp->data->fd; in single_send()
1426 my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_send() argument
1433 n = php_pollfd_for_ms(s, POLLOUT, ftp->timeout_sec * 1000); in my_send()
1448 sent = single_send(ftp, s, buf, size); in my_send()
1463 my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len) in my_recv() argument
1472 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_recv()
1487 if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) { in my_recv()
1488 handle = ftp->ssl_handle; in my_recv()
1489 fd = ftp->fd; in my_recv()
1490 } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) { in my_recv()
1491 handle = ftp->data->ssl_handle; in my_recv()
1492 fd = ftp->data->fd; in my_recv()
1542 data_available(ftpbuf_t *ftp, php_socket_t s) in data_available() argument
1565 data_writeable(ftpbuf_t *ftp, php_socket_t s) in data_writeable() argument
1589 my_accept(ftpbuf_t *ftp, php_socket_t s, struct sockaddr *addr, socklen_t *addrlen) in my_accept() argument
1593 n = php_pollfd_for_ms(s, PHP_POLLREADABLE, ftp->timeout_sec * 1000); in my_accept()
1613 ftp_getdata(ftpbuf_t *ftp) in ftp_getdata() argument
1627 if (ftp->pasv && !ftp_pasv(ftp, 1)) { in ftp_getdata()
1634 data->type = ftp->type; in ftp_getdata()
1636 sa = (struct sockaddr *) &ftp->localaddr; in ftp_getdata()
1644 if (ftp->pasv) { in ftp_getdata()
1646 ftp->pasv = 1; in ftp_getdata()
1650 size = php_sockaddr_size(&ftp->pasvaddr); in ftp_getdata()
1651 tv.tv_sec = ftp->timeout_sec; in ftp_getdata()
1653 if (php_connect_nonb(fd, (struct sockaddr*) &ftp->pasvaddr, size, &tv) == -1) { in ftp_getdata()
1660 ftp->data = data; in ftp_getdata()
1701 if (!ftp_putcmd(ftp, "EPRT", sizeof("EPRT")-1, eprtarg, eprtarg_len)) { in ftp_getdata()
1705 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1709 ftp->data = data; in ftp_getdata()
1722 if (!ftp_putcmd(ftp, "PORT", sizeof("PORT")-1, arg, arg_len)) { in ftp_getdata()
1725 if (!ftp_getresp(ftp) || ftp->resp != 200) { in ftp_getdata()
1729 ftp->data = data; in ftp_getdata()
1743 data_accept(databuf_t *data, ftpbuf_t *ftp) in data_accept() argument
1759 data->fd = my_accept(ftp, data->listener, (struct sockaddr*) &addr, &size); in data_accept()
1772 if (ftp->use_ssl && ftp->use_ssl_for_data) { in data_accept()
1773 ctx = SSL_get_SSL_CTX(ftp->ssl_handle); in data_accept()
1787 if (ftp->old_ssl) { in data_accept()
1788 SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle); in data_accept()
1792 session = SSL_get_session(ftp->ssl_handle); in data_accept()
1855 static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) { in ftp_ssl_shutdown() argument
1874 while (!done && data_available(ftp, fd)) { in ftp_ssl_shutdown()
1918 data_close(ftpbuf_t *ftp, databuf_t *data) in data_close() argument
1927 ftp_ssl_shutdown(ftp, data->listener, data->ssl_handle); in data_close()
1937 ftp_ssl_shutdown(ftp, data->fd, data->ssl_handle); in data_close()
1943 if (ftp) { in data_close()
1944 ftp->data = NULL; in data_close()
1953 ftp_genlist(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, const char *path, const size_t pa… in ftp_genlist() argument
1971 if (!ftp_type(ftp, FTPTYPE_ASCII)) { in ftp_genlist()
1975 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_genlist()
1978 ftp->data = data; in ftp_genlist()
1980 if (!ftp_putcmd(ftp, cmd, cmd_len, path, path_len)) { in ftp_genlist()
1983 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125 && ftp->resp != 226)) { in ftp_genlist()
1988 if (ftp->resp == 226) { in ftp_genlist()
1989 ftp->data = data_close(ftp, data); in ftp_genlist()
1995 if ((data = data_accept(data, ftp)) == NULL) { in ftp_genlist()
2001 while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_genlist()
2017 ftp->data = data_close(ftp, data); in ftp_genlist()
2040 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_genlist()
2047 ftp->data = data_close(ftp, data); in ftp_genlist()
2057 ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t… in ftp_nb_get() argument
2062 if (ftp == NULL) { in ftp_nb_get()
2066 if (ftp->data != NULL) { in ftp_nb_get()
2069 data_close(ftp, ftp->data); in ftp_nb_get()
2070 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_get()
2075 if (!ftp_type(ftp, type)) { in ftp_nb_get()
2079 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_get()
2089 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_get()
2092 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_get()
2097 if (!ftp_putcmd(ftp, "RETR", sizeof("RETR")-1, path, path_len)) { in ftp_nb_get()
2100 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_get()
2104 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_get()
2108 ftp->data = data; in ftp_nb_get()
2109 ftp->stream = outstream; in ftp_nb_get()
2110 ftp->lastch = 0; in ftp_nb_get()
2111 ftp->nb = 1; in ftp_nb_get()
2113 return (ftp_nb_continue_read(ftp)); in ftp_nb_get()
2116 ftp->data = data_close(ftp, data); in ftp_nb_get()
2123 ftp_nb_continue_read(ftpbuf_t *ftp) in ftp_nb_continue_read() argument
2131 data = ftp->data; in ftp_nb_continue_read()
2134 if (!data_available(ftp, data->fd)) { in ftp_nb_continue_read()
2138 type = ftp->type; in ftp_nb_continue_read()
2140 lastch = ftp->lastch; in ftp_nb_continue_read()
2141 if ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) { in ftp_nb_continue_read()
2149 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2152 php_stream_putc(ftp->stream, *ptr); in ftp_nb_continue_read()
2156 } else if (rcvd != php_stream_write(ftp->stream, data->buf, rcvd)) { in ftp_nb_continue_read()
2160 ftp->lastch = lastch; in ftp_nb_continue_read()
2165 php_stream_putc(ftp->stream, '\r'); in ftp_nb_continue_read()
2168 ftp->data = data = data_close(ftp, data); in ftp_nb_continue_read()
2170 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_read()
2174 ftp->nb = 0; in ftp_nb_continue_read()
2177 ftp->nb = 0; in ftp_nb_continue_read()
2178 ftp->data = data_close(ftp, data); in ftp_nb_continue_read()
2185 ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t … in ftp_nb_put() argument
2190 if (ftp == NULL) { in ftp_nb_put()
2193 if (!ftp_type(ftp, type)) { in ftp_nb_put()
2196 if ((data = ftp_getdata(ftp)) == NULL) { in ftp_nb_put()
2205 if (!ftp_putcmd(ftp, "REST", sizeof("REST")-1, arg, arg_len)) { in ftp_nb_put()
2208 if (!ftp_getresp(ftp) || (ftp->resp != 350)) { in ftp_nb_put()
2213 if (!ftp_putcmd(ftp, "STOR", sizeof("STOR")-1, path, path_len)) { in ftp_nb_put()
2216 if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) { in ftp_nb_put()
2219 if ((data = data_accept(data, ftp)) == NULL) { in ftp_nb_put()
2222 ftp->data = data; in ftp_nb_put()
2223 ftp->stream = instream; in ftp_nb_put()
2224 ftp->lastch = 0; in ftp_nb_put()
2225 ftp->nb = 1; in ftp_nb_put()
2227 return (ftp_nb_continue_write(ftp)); in ftp_nb_put()
2230 ftp->data = data_close(ftp, data); in ftp_nb_put()
2238 ftp_nb_continue_write(ftpbuf_t *ftp) in ftp_nb_continue_write() argument
2245 if (!data_writeable(ftp, ftp->data->fd)) { in ftp_nb_continue_write()
2250 ptr = ftp->data->buf; in ftp_nb_continue_write()
2251 while (!php_stream_eof(ftp->stream) && (ch = php_stream_getc(ftp->stream)) != EOF) { in ftp_nb_continue_write()
2253 if (ch == '\n' && ftp->type == FTPTYPE_ASCII) { in ftp_nb_continue_write()
2263 if (my_send(ftp, ftp->data->fd, ftp->data->buf, size) != size) { in ftp_nb_continue_write()
2270 if (size && my_send(ftp, ftp->data->fd, ftp->data->buf, size) != size) { in ftp_nb_continue_write()
2273 ftp->data = data_close(ftp, ftp->data); in ftp_nb_continue_write()
2275 if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) { in ftp_nb_continue_write()
2278 ftp->nb = 0; in ftp_nb_continue_write()
2281 ftp->data = data_close(ftp, ftp->data); in ftp_nb_continue_write()
2282 ftp->nb = 0; in ftp_nb_continue_write()