1999-09-20 14:10:25 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 17:33:29 +00:00
|
|
|
| PHP Version 5 |
|
1999-09-20 14:10:25 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2008-12-31 11:15:49 +00:00
|
|
|
| Copyright (c) 1997-2009 The PHP Group |
|
1999-09-20 14:10:25 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2001-06-19 21:25:53 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 12:51:34 +00:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2001-06-19 21:25:53 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-09-20 14:10:25 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 08:29:35 +00:00
|
|
|
| Authors: Andrew Skalski <askalski@chek.com> |
|
2002-07-26 13:03:08 +00:00
|
|
|
| Stefan Esser <sesser@php.net> (resume functions) |
|
1999-09-20 14:10:25 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
1999-09-16 15:57:51 +00:00
|
|
|
|
1999-09-22 16:07:41 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2000-07-02 23:46:51 +00:00
|
|
|
#ifndef FTP_H
|
|
|
|
#define FTP_H
|
1999-09-16 15:57:51 +00:00
|
|
|
|
2002-01-06 23:10:54 +00:00
|
|
|
#include "php_network.h"
|
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
#include <stdio.h>
|
2000-05-23 10:12:42 +00:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
1999-09-20 14:10:25 +00:00
|
|
|
#include <netinet/in.h>
|
2000-05-23 08:05:22 +00:00
|
|
|
#endif
|
1999-09-20 14:10:25 +00:00
|
|
|
|
2002-01-02 14:58:17 +00:00
|
|
|
#define FTP_DEFAULT_TIMEOUT 90
|
2002-07-26 13:03:08 +00:00
|
|
|
#define FTP_DEFAULT_AUTOSEEK 1
|
2002-07-26 22:00:25 +00:00
|
|
|
#define PHP_FTP_FAILED 0
|
|
|
|
#define PHP_FTP_FINISHED 1
|
|
|
|
#define PHP_FTP_MOREDATA 2
|
2002-01-02 14:58:17 +00:00
|
|
|
|
|
|
|
/* XXX this should be configurable at runtime XXX */
|
1999-09-20 14:10:25 +00:00
|
|
|
#define FTP_BUFSIZE 4096
|
|
|
|
|
|
|
|
typedef enum ftptype {
|
2006-11-24 12:39:39 +00:00
|
|
|
FTPTYPE_ASCII=1,
|
2001-05-27 19:12:21 +00:00
|
|
|
FTPTYPE_IMAGE
|
1999-09-20 14:10:25 +00:00
|
|
|
} ftptype_t;
|
|
|
|
|
2002-07-26 22:00:25 +00:00
|
|
|
typedef struct databuf
|
|
|
|
{
|
|
|
|
int listener; /* listener socket */
|
2003-02-28 21:03:36 +00:00
|
|
|
php_socket_t fd; /* data connection */
|
2002-07-26 22:00:25 +00:00
|
|
|
ftptype_t type; /* transfer type */
|
|
|
|
char buf[FTP_BUFSIZE]; /* data buffer */
|
2003-12-06 16:12:10 +00:00
|
|
|
#if HAVE_OPENSSL_EXT
|
2002-10-03 11:33:05 +00:00
|
|
|
SSL *ssl_handle; /* ssl handle */
|
|
|
|
int ssl_active; /* flag if ssl is active or not */
|
2002-10-03 12:16:44 +00:00
|
|
|
#endif
|
2002-07-26 22:00:25 +00:00
|
|
|
} databuf_t;
|
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
typedef struct ftpbuf
|
|
|
|
{
|
2003-02-28 21:03:36 +00:00
|
|
|
php_socket_t fd; /* control connection */
|
2002-01-06 23:10:54 +00:00
|
|
|
php_sockaddr_storage localaddr; /* local address */
|
1999-09-20 14:10:25 +00:00
|
|
|
int resp; /* last response code */
|
|
|
|
char inbuf[FTP_BUFSIZE]; /* last response text */
|
1999-11-18 20:29:32 +00:00
|
|
|
char *extra; /* extra characters */
|
|
|
|
int extralen; /* number of extra chars */
|
|
|
|
char outbuf[FTP_BUFSIZE]; /* command output buffer */
|
1999-09-20 14:10:25 +00:00
|
|
|
char *pwd; /* cached pwd */
|
|
|
|
char *syst; /* cached system type */
|
|
|
|
ftptype_t type; /* current transfer type */
|
1999-09-27 14:07:09 +00:00
|
|
|
int pasv; /* 0=off; 1=pasv; 2=ready */
|
2002-01-06 23:10:54 +00:00
|
|
|
php_sockaddr_storage pasvaddr; /* passive mode address */
|
2002-01-02 14:58:17 +00:00
|
|
|
long timeout_sec; /* User configureable timeout (seconds) */
|
2002-07-26 13:03:08 +00:00
|
|
|
int autoseek; /* User configureable autoseek flag */
|
2002-07-26 22:00:25 +00:00
|
|
|
|
2002-10-03 09:10:24 +00:00
|
|
|
int nb; /* "nonblocking" transfer in progress */
|
|
|
|
databuf_t *data; /* Data connection for "nonblocking" transfers */
|
|
|
|
php_stream *stream; /* output stream for "nonblocking" transfers */
|
2002-07-26 22:00:25 +00:00
|
|
|
int lastch; /* last char of previous call */
|
|
|
|
int direction; /* recv = 0 / send = 1 */
|
|
|
|
int closestream;/* close or not close stream */
|
2003-12-06 16:12:10 +00:00
|
|
|
#if HAVE_OPENSSL_EXT
|
2002-10-03 11:33:05 +00:00
|
|
|
int use_ssl; /* enable(1) or disable(0) ssl */
|
|
|
|
int use_ssl_for_data; /* en/disable ssl for the dataconnection */
|
|
|
|
int old_ssl; /* old mode = forced data encryption */
|
|
|
|
SSL *ssl_handle; /* handle for control connection */
|
|
|
|
int ssl_active; /* ssl active on control conn */
|
|
|
|
#endif
|
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
} ftpbuf_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* open a FTP connection, returns ftpbuf (NULL on error)
|
|
|
|
* port is the ftp port in network byte order, or 0 for the default
|
|
|
|
*/
|
2002-08-25 22:17:56 +00:00
|
|
|
ftpbuf_t* ftp_open(const char *host, short port, long timeout_sec TSRMLS_DC);
|
1999-09-20 14:10:25 +00:00
|
|
|
|
|
|
|
/* quits from the ftp session (it still needs to be closed)
|
|
|
|
* return true on success, false on error
|
|
|
|
*/
|
|
|
|
int ftp_quit(ftpbuf_t *ftp);
|
|
|
|
|
|
|
|
/* frees up any cached data held in the ftp buffer */
|
|
|
|
void ftp_gc(ftpbuf_t *ftp);
|
|
|
|
|
|
|
|
/* close the FTP connection and return NULL */
|
|
|
|
ftpbuf_t* ftp_close(ftpbuf_t *ftp);
|
|
|
|
|
|
|
|
/* logs into the FTP server, returns true on success, false on error */
|
2003-01-07 03:44:12 +00:00
|
|
|
int ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC);
|
1999-09-20 14:10:25 +00:00
|
|
|
|
|
|
|
/* reinitializes the connection, returns true on success, false on error */
|
|
|
|
int ftp_reinit(ftpbuf_t *ftp);
|
|
|
|
|
|
|
|
/* returns the remote system type (NULL on error) */
|
|
|
|
const char* ftp_syst(ftpbuf_t *ftp);
|
|
|
|
|
|
|
|
/* returns the present working directory (NULL on error) */
|
|
|
|
const char* ftp_pwd(ftpbuf_t *ftp);
|
|
|
|
|
2000-09-13 22:00:31 +00:00
|
|
|
/* exec a command [special features], return true on success, false on error */
|
|
|
|
int ftp_exec(ftpbuf_t *ftp, const char *cmd);
|
|
|
|
|
2003-01-31 04:54:57 +00:00
|
|
|
/* send a raw ftp command, return response as a hashtable, NULL on error */
|
|
|
|
void ftp_raw(ftpbuf_t *ftp, const char *cmd, zval *return_value);
|
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
/* changes directories, return true on success, false on error */
|
|
|
|
int ftp_chdir(ftpbuf_t *ftp, const char *dir);
|
|
|
|
|
|
|
|
/* changes to parent directory, return true on success, false on error */
|
|
|
|
int ftp_cdup(ftpbuf_t *ftp);
|
1999-09-16 15:57:51 +00:00
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
/* creates a directory, return the directory name on success, NULL on error.
|
|
|
|
* the return value must be freed
|
|
|
|
*/
|
|
|
|
char* ftp_mkdir(ftpbuf_t *ftp, const char *dir);
|
1999-09-16 15:57:51 +00:00
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
/* removes a directory, return true on success, false on error */
|
|
|
|
int ftp_rmdir(ftpbuf_t *ftp, const char *dir);
|
1999-09-16 15:57:51 +00:00
|
|
|
|
2003-01-27 02:54:12 +00:00
|
|
|
/* Set permissions on a file */
|
2003-01-27 19:51:50 +00:00
|
|
|
int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len);
|
2003-01-27 02:54:12 +00:00
|
|
|
|
2003-09-18 17:36:08 +00:00
|
|
|
/* Allocate space on remote server with ALLO command
|
|
|
|
* Many servers will respond with 202 Allocation not necessary,
|
|
|
|
* however some servers will not accept STOR or APPE until ALLO is confirmed.
|
|
|
|
* If response is passed, it is estrdup()ed from ftp->inbuf and must be freed
|
|
|
|
* or assigned to a zval returned to the user */
|
|
|
|
int ftp_alloc(ftpbuf_t *ftp, const int size, char **response);
|
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
/* returns a NULL-terminated array of filenames in the given path
|
|
|
|
* or NULL on error. the return array must be freed (but don't
|
|
|
|
* free the array elements)
|
|
|
|
*/
|
2003-01-07 03:44:12 +00:00
|
|
|
char** ftp_nlist(ftpbuf_t *ftp, const char *path TSRMLS_DC);
|
1999-09-16 15:57:51 +00:00
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
/* returns a NULL-terminated array of lines returned by the ftp
|
|
|
|
* LIST command for the given path or NULL on error. the return
|
|
|
|
* array must be freed (but don't
|
|
|
|
* free the array elements)
|
|
|
|
*/
|
2003-01-07 03:44:12 +00:00
|
|
|
char** ftp_list(ftpbuf_t *ftp, const char *path, int recursive TSRMLS_DC);
|
1999-09-16 15:57:51 +00:00
|
|
|
|
1999-09-27 14:07:09 +00:00
|
|
|
/* switches passive mode on or off
|
|
|
|
* returns true on success, false on error
|
|
|
|
*/
|
|
|
|
int ftp_pasv(ftpbuf_t *ftp, int pasv);
|
|
|
|
|
1999-09-20 14:10:25 +00:00
|
|
|
/* retrieves a file and saves its contents to outfp
|
|
|
|
* returns true on success, false on error
|
|
|
|
*/
|
2003-01-07 13:02:43 +00:00
|
|
|
int ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, int resumepos TSRMLS_DC);
|
1999-09-16 15:57:51 +00:00
|
|
|
|
2001-07-17 05:53:03 +00:00
|
|
|
/* stores the data from a file, socket, or process as a file on the remote server
|
1999-09-20 14:10:25 +00:00
|
|
|
* returns true on success, false on error
|
|
|
|
*/
|
2003-01-07 13:02:43 +00:00
|
|
|
int ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, int startpos TSRMLS_DC);
|
1999-09-16 15:57:51 +00:00
|
|
|
|
1999-09-27 14:07:09 +00:00
|
|
|
/* returns the size of the given file, or -1 on error */
|
|
|
|
int ftp_size(ftpbuf_t *ftp, const char *path);
|
|
|
|
|
1999-10-04 18:30:37 +00:00
|
|
|
/* returns the last modified time of the given file, or -1 on error */
|
1999-09-27 14:07:09 +00:00
|
|
|
time_t ftp_mdtm(ftpbuf_t *ftp, const char *path);
|
|
|
|
|
1999-10-04 18:30:37 +00:00
|
|
|
/* renames a file on the server */
|
|
|
|
int ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest);
|
|
|
|
|
|
|
|
/* deletes the file from the server */
|
|
|
|
int ftp_delete(ftpbuf_t *ftp, const char *path);
|
|
|
|
|
2000-02-22 20:50:00 +00:00
|
|
|
/* sends a SITE command to the server */
|
|
|
|
int ftp_site(ftpbuf_t *ftp, const char *cmd);
|
|
|
|
|
2002-07-26 22:00:25 +00:00
|
|
|
/* retrieves part of a file and saves its contents to outfp
|
|
|
|
* returns true on success, false on error
|
|
|
|
*/
|
2003-01-07 03:44:12 +00:00
|
|
|
int ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, int resumepos TSRMLS_DC);
|
2002-07-26 22:00:25 +00:00
|
|
|
|
|
|
|
/* stores the data from a file, socket, or process as a file on the remote server
|
|
|
|
* returns true on success, false on error
|
|
|
|
*/
|
2003-01-07 03:44:12 +00:00
|
|
|
int ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, int startpos TSRMLS_DC);
|
2002-07-26 22:00:25 +00:00
|
|
|
|
2002-10-03 09:10:24 +00:00
|
|
|
/* continues a previous nb_(f)get command
|
2002-07-26 22:00:25 +00:00
|
|
|
*/
|
2003-01-07 13:02:43 +00:00
|
|
|
int ftp_nb_continue_read(ftpbuf_t *ftp TSRMLS_DC);
|
2002-07-26 22:00:25 +00:00
|
|
|
|
2002-10-03 09:10:24 +00:00
|
|
|
/* continues a previous nb_(f)put command
|
2002-07-26 22:00:25 +00:00
|
|
|
*/
|
2003-01-07 13:02:43 +00:00
|
|
|
int ftp_nb_continue_write(ftpbuf_t *ftp TSRMLS_DC);
|
2002-07-26 22:00:25 +00:00
|
|
|
|
|
|
|
|
1999-09-16 15:57:51 +00:00
|
|
|
#endif
|