php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
ftp.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Andrew Skalski <askalski@chek.com> |
14 | Stefan Esser <sesser@php.net> (resume functions) |
15 +----------------------------------------------------------------------+
16 */
17
18#ifndef FTP_H
19#define FTP_H
20
21#include "php_network.h"
22
23#include <stdio.h>
24#ifdef HAVE_NETINET_IN_H
25#include <netinet/in.h>
26#endif
27
28#define FTP_DEFAULT_TIMEOUT 90
29#define FTP_DEFAULT_AUTOSEEK 1
30#define FTP_DEFAULT_USEPASVADDRESS 1
31#define PHP_FTP_FAILED 0
32#define PHP_FTP_FINISHED 1
33#define PHP_FTP_MOREDATA 2
34
35/* XXX this should be configurable at runtime XXX */
36#define FTP_BUFSIZE 4096
37
42
43typedef struct databuf
44{
45 int listener; /* listener socket */
46 php_socket_t fd; /* data connection */
47 ftptype_t type; /* transfer type */
48 char buf[FTP_BUFSIZE]; /* data buffer */
49#ifdef HAVE_FTP_SSL
50 SSL *ssl_handle; /* ssl handle */
51 int ssl_active; /* flag if ssl is active or not */
52#endif
54
55typedef struct ftpbuf
56{
57 php_socket_t fd; /* control connection */
58 php_sockaddr_storage localaddr; /* local address */
59 int resp; /* last response code */
60 char inbuf[FTP_BUFSIZE]; /* last response text */
61 char *extra; /* extra characters */
62 int extralen; /* number of extra chars */
63 char outbuf[FTP_BUFSIZE]; /* command output buffer */
64 char *pwd; /* cached pwd */
65 char *syst; /* cached system type */
66 ftptype_t type; /* current transfer type */
67 int pasv; /* 0=off; 1=pasv; 2=ready */
68 php_sockaddr_storage pasvaddr; /* passive mode address */
69 zend_long timeout_sec; /* User configurable timeout (seconds) */
70 int autoseek; /* User configurable autoseek flag */
71 int usepasvaddress; /* Use the address returned by the pasv command */
72
73 databuf_t *data; /* Data connection for "nonblocking" transfers */
74 php_stream *stream; /* output stream for "nonblocking" transfers */
75 bool nb; /* "nonblocking" transfer in progress */
76 char lastch; /* last char of previous call */
77 bool direction; /* recv = 0 / send = 1 */
78 bool closestream;/* close or not close stream */
79#ifdef HAVE_FTP_SSL
80 bool use_ssl; /* enable(1) or disable(0) ssl */
81 bool use_ssl_for_data; /* en/disable ssl for the dataconnection */
82 bool old_ssl; /* old mode = forced data encryption */
83 bool ssl_active; /* ssl active on control conn */
84 SSL *ssl_handle; /* handle for control connection */
85 SSL_SESSION *last_ssl_session; /* last negotiated session */
86#endif
87
89
90
91
92/* open a FTP connection, returns ftpbuf (NULL on error)
93 * port is the ftp port in network byte order, or 0 for the default
94 */
95ftpbuf_t* ftp_open(const char *host, short port, zend_long timeout_sec);
96
97/* quits from the ftp session (it still needs to be closed)
98 * return true on success, false on error
99 */
100int ftp_quit(ftpbuf_t *ftp);
101
102/* frees up any cached data held in the ftp buffer */
103void ftp_gc(ftpbuf_t *ftp);
104
105/* close the FTP connection and return NULL */
107
108/* logs into the FTP server, returns true on success, false on error */
109int ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len);
110
111/* reinitializes the connection, returns true on success, false on error */
112int ftp_reinit(ftpbuf_t *ftp);
113
114/* returns the remote system type (NULL on error) */
115const char* ftp_syst(ftpbuf_t *ftp);
116
117/* returns the present working directory (NULL on error) */
118const char* ftp_pwd(ftpbuf_t *ftp);
119
120/* exec a command [special features], return true on success, false on error */
121int ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len);
122
123/* send a raw ftp command, return response as a hashtable, NULL on error */
124void ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value);
125
126/* changes directories, return true on success, false on error */
127int ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len);
128
129/* changes to parent directory, return true on success, false on error */
130int ftp_cdup(ftpbuf_t *ftp);
131
132/* creates a directory, return the directory name on success, NULL on error.
133 * the return value must be freed
134 */
135zend_string* ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len);
136
137/* removes a directory, return true on success, false on error */
138int ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len);
139
140/* Set permissions on a file */
141int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len);
142
143/* Allocate space on remote server with ALLO command
144 * Many servers will respond with 202 Allocation not necessary,
145 * however some servers will not accept STOR or APPE until ALLO is confirmed.
146 * If response is passed, it is estrdup()ed from ftp->inbuf and must be freed
147 * or assigned to a zval returned to the user */
148int ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response);
149
150/* returns a NULL-terminated array of filenames in the given path
151 * or NULL on error. the return array must be freed (but don't
152 * free the array elements)
153 */
154char** ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len);
155
156/* returns a NULL-terminated array of lines returned by the ftp
157 * LIST command for the given path or NULL on error. the return
158 * array must be freed (but don't
159 * free the array elements)
160 */
161char** ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive);
162
163/* populates a hashtable with the facts contained in one line of
164 * an MLSD response.
165 */
166int ftp_mlsd_parse_line(HashTable *ht, const char *input);
167
168/* returns a NULL-terminated array of lines returned by the ftp
169 * MLSD command for the given path or NULL on error. the return
170 * array must be freed (but don't
171 * free the array elements)
172 */
173char** ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len);
174
175/* switches passive mode on or off
176 * returns true on success, false on error
177 */
178int ftp_pasv(ftpbuf_t *ftp, int pasv);
179
180/* retrieves a file and saves its contents to outfp
181 * returns true on success, false on error
182 */
183int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos);
184
185/* stores the data from a file, socket, or process as a file on the remote server
186 * returns true on success, false on error
187 */
188int ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos);
189
190/* append the data from a file, socket, or process as a file on the remote server
191 * returns true on success, false on error
192 */
193int ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type);
194
195/* returns the size of the given file, or -1 on error */
196zend_long ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len);
197
198/* returns the last modified time of the given file, or -1 on error */
199time_t ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len);
200
201/* renames a file on the server */
202int ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len);
203
204/* deletes the file from the server */
205int ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len);
206
207/* sends a SITE command to the server */
208int ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len);
209
210/* retrieves part of a file and saves its contents to outfp
211 * returns true on success, false on error
212 */
213int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos);
214
215/* stores the data from a file, socket, or process as a file on the remote server
216 * returns true on success, false on error
217 */
218int ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos);
219
220/* continues a previous nb_(f)get command
221 */
223
224/* continues a previous nb_(f)put command
225 */
227
228
229#endif
dir(string $directory, $context=null)
zend_ffi_type * type
Definition ffi.c:3812
new_type size
Definition ffi.c:4365
HashTable * ht
Definition ffi.c:4838
int ftp_delete(ftpbuf_t *ftp, const char *path, const size_t path_len)
Definition ftp.c:1220
int ftp_rename(ftpbuf_t *ftp, const char *src, const size_t src_len, const char *dest, const size_t dest_len)
Definition ftp.c:1238
int ftp_append(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type)
Definition ftp.c:1110
time_t ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len)
Definition ftp.c:1173
struct ftpbuf ftpbuf_t
int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos)
Definition ftp.c:886
int ftp_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos)
Definition ftp.c:1052
int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, const size_t path_len, ftptype_t type, zend_long resumepos)
Definition ftp.c:2144
char ** ftp_list(ftpbuf_t *ftp, const char *path, const size_t path_len, int recursive)
Definition ftp.c:702
int ftp_mlsd_parse_line(HashTable *ht, const char *input)
Definition ftp.c:718
const char * ftp_syst(ftpbuf_t *ftp)
Definition ftp.c:425
zend_string * ftp_mkdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len)
Definition ftp.c:577
int ftp_cdup(ftpbuf_t *ftp)
Definition ftp.c:554
int ftp_site(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len)
Definition ftp.c:1261
char ** ftp_nlist(ftpbuf_t *ftp, const char *path, const size_t path_len)
Definition ftp.c:694
char ** ftp_mlsd(ftpbuf_t *ftp, const char *path, const size_t path_len)
Definition ftp.c:710
ftpbuf_t * ftp_close(ftpbuf_t *ftp)
Definition ftp.c:165
int ftp_login(ftpbuf_t *ftp, const char *user, const size_t user_len, const char *pass, const size_t pass_len)
Definition ftp.c:253
int ftp_chdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len)
Definition ftp.c:531
int ftp_nb_continue_read(ftpbuf_t *ftp)
Definition ftp.c:2210
ftptype
Definition ftp.h:38
@ FTPTYPE_ASCII
Definition ftp.h:39
@ FTPTYPE_IMAGE
Definition ftp.h:40
int ftp_reinit(ftpbuf_t *ftp)
Definition ftp.c:402
int ftp_rmdir(ftpbuf_t *ftp, const char *dir, const size_t dir_len)
Definition ftp.c:608
ftpbuf_t * ftp_open(const char *host, short port, zend_long timeout_sec)
Definition ftp.c:117
int ftp_quit(ftpbuf_t *ftp)
Definition ftp.c:213
int ftp_nb_continue_write(ftpbuf_t *ftp)
Definition ftp.c:2325
int ftp_alloc(ftpbuf_t *ftp, const zend_long size, zend_string **response)
Definition ftp.c:657
void ftp_gc(ftpbuf_t *ftp)
Definition ftp.c:195
const char * ftp_pwd(ftpbuf_t *ftp)
Definition ftp.c:460
int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len)
Definition ftp.c:625
int ftp_exec(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len)
Definition ftp.c:493
#define FTP_BUFSIZE
Definition ftp.h:36
struct databuf databuf_t
enum ftptype ftptype_t
int ftp_nb_put(ftpbuf_t *ftp, const char *path, const size_t path_len, php_stream *instream, ftptype_t type, zend_long startpos)
Definition ftp.c:2272
void ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value)
Definition ftp.c:511
int ftp_pasv(ftpbuf_t *ftp, int pasv)
Definition ftp.c:793
zend_long ftp_size(ftpbuf_t *ftp, const char *path, const size_t path_len)
Definition ftp.c:1153
char * mode
size_t filename_len
#define pass(a, b, c, mul)
Definition hash_tiger.c:50
int php_socket_t
struct _php_stream php_stream
Definition php_streams.h:96
Definition ftp.h:44
int listener
Definition ftp.h:45
php_socket_t fd
Definition ftp.h:46
char buf[FTP_BUFSIZE]
Definition ftp.h:48
ftptype_t type
Definition ftp.h:47
Definition ftp.h:56
php_stream * stream
Definition ftp.h:74
int usepasvaddress
Definition ftp.h:71
php_sockaddr_storage pasvaddr
Definition ftp.h:68
int resp
Definition ftp.h:59
char * syst
Definition ftp.h:65
bool closestream
Definition ftp.h:78
php_sockaddr_storage localaddr
Definition ftp.h:58
databuf_t * data
Definition ftp.h:73
int pasv
Definition ftp.h:67
zend_long timeout_sec
Definition ftp.h:69
char lastch
Definition ftp.h:76
int extralen
Definition ftp.h:62
bool direction
Definition ftp.h:77
char outbuf[FTP_BUFSIZE]
Definition ftp.h:63
php_socket_t fd
Definition ftp.h:57
char inbuf[FTP_BUFSIZE]
Definition ftp.h:60
char * extra
Definition ftp.h:61
char * pwd
Definition ftp.h:64
int autoseek
Definition ftp.h:70
bool nb
Definition ftp.h:75
ftptype_t type
Definition ftp.h:66
struct _zval_struct zval
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
struct _zend_array HashTable
Definition zend_types.h:386
zval * return_value