summaryrefslogtreecommitdiff
path: root/ext/ftp
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ftp')
-rw-r--r--ext/ftp/Makefile.am4
-rw-r--r--ext/ftp/config.h.stub2
-rw-r--r--ext/ftp/config.m418
-rw-r--r--ext/ftp/ftp.c1165
-rw-r--r--ext/ftp/ftp.h158
-rw-r--r--ext/ftp/php_ftp.c796
-rw-r--r--ext/ftp/php_ftp.h79
7 files changed, 0 insertions, 2222 deletions
diff --git a/ext/ftp/Makefile.am b/ext/ftp/Makefile.am
deleted file mode 100644
index 8ba82c10d1..0000000000
--- a/ext/ftp/Makefile.am
+++ /dev/null
@@ -1,4 +0,0 @@
-# $Id$
-
-noinst_LTLIBRARIES=libphpext_ftp.la
-libphpext_ftp_la_SOURCES=php_ftp.c ftp.c
diff --git a/ext/ftp/config.h.stub b/ext/ftp/config.h.stub
deleted file mode 100644
index d63248456c..0000000000
--- a/ext/ftp/config.h.stub
+++ /dev/null
@@ -1,2 +0,0 @@
-/* define if you want to use the ftp extension */
-#define HAVE_FTP 0
diff --git a/ext/ftp/config.m4 b/ext/ftp/config.m4
deleted file mode 100644
index 7b01e6b54d..0000000000
--- a/ext/ftp/config.m4
+++ /dev/null
@@ -1,18 +0,0 @@
-dnl $Id$
-dnl config.m4 for extension ftp
-dnl don't forget to call PHP_EXTENSION(ftp)
-
-AC_MSG_CHECKING(for FTP support)
-AC_ARG_WITH(ftp,
-[ --with-ftp Include FTP support.],
-[
- if test "$withval" != "no"; then
- AC_DEFINE(HAVE_FTP)
- PHP_EXTENSION(ftp)
- AC_MSG_RESULT(yes)
- else
- AC_MSG_RESULT(no)
- fi
-],[
- AC_MSG_RESULT(no)
-])
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
deleted file mode 100644
index 4ced3839a0..0000000000
--- a/ext/ftp/ftp.c
+++ /dev/null
@@ -1,1165 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP HTML Embedded Scripting Language Version 3.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
- +----------------------------------------------------------------------+
- | This program is free software; you can redistribute it and/or modify |
- | it under the terms of one of the following licenses: |
- | |
- | A) the GNU General Public License as published by the Free Software |
- | Foundation; either version 2 of the License, or (at your option) |
- | any later version. |
- | |
- | B) the PHP License as published by the PHP Development Team and |
- | included in the distribution in the file: LICENSE |
- | |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU General Public License for more details. |
- | |
- | You should have received a copy of both licenses referred to here. |
- | If you did not, or have any questions about PHP licensing, please |
- | contact core@php.net. |
- +----------------------------------------------------------------------+
- | Authors: |
- | Andrew Skalski <askalski@chek.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-
-#if HAVE_FTP
-
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <errno.h>
-
-#if HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-
-#include "ftp.h"
-
-/* sends an ftp command, returns true on success, false on error.
- * it sends the string "cmd args\r\n" if args is non-null, or
- * "cmd\r\n" if args is null
- */
-static int ftp_putcmd( ftpbuf_t *ftp,
- const char *cmd,
- const char *args);
-
-/* wrapper around send/recv to handle timeouts */
-static int my_send(int s, void *buf, size_t len);
-static int my_recv(int s, void *buf, size_t len);
-static int my_connect(int s, const struct sockaddr *addr,
- int addrlen);
-static int my_accept(int s, struct sockaddr *addr, int *addrlen);
-
-/* reads a line the socket , returns true on success, false on error */
-static int ftp_readline(ftpbuf_t *ftp);
-
-/* reads an ftp response, returns true on success, false on error */
-static int ftp_getresp(ftpbuf_t *ftp);
-
-/* sets the ftp transfer type */
-static int ftp_type(ftpbuf_t *ftp, ftptype_t type);
-
-/* opens up a data stream */
-static databuf_t* ftp_getdata(ftpbuf_t *ftp);
-
-/* accepts the data connection, returns updated data buffer */
-static databuf_t* data_accept(databuf_t *data);
-
-/* closes the data connection, returns NULL */
-static databuf_t* data_close(databuf_t *data);
-
-/* generic file lister */
-static char** ftp_genlist(ftpbuf_t *ftp,
- const char *cmd, const char *path);
-
-/* IP and port conversion box */
-union ipbox {
- unsigned long l[2];
- unsigned short s[4];
- unsigned char c[8];
-};
-
-
-ftpbuf_t*
-ftp_open(const char *host, short port)
-{
- int fd = -1;
- ftpbuf_t *ftp;
- struct sockaddr_in addr;
- struct hostent *he;
- int size;
-
-
- /* set up the address */
- if ((he = gethostbyname(host)) == NULL) {
-#if 0
- herror("gethostbyname");
-#endif
- return NULL;
- }
-
- memset(&addr, 0, sizeof(addr));
- memcpy(&addr.sin_addr, he->h_addr, he->h_length);
- addr.sin_family = AF_INET;
- addr.sin_port = port ? port : htons(21);
-
-
- /* alloc the ftp structure */
- ftp = calloc(1, sizeof(*ftp));
- if (ftp == NULL) {
- perror("calloc");
- return NULL;
- }
-
- /* connect */
- if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
- perror("socket");
- goto bail;
- }
-
- if (my_connect(fd, (struct sockaddr*) &addr, sizeof(addr)) == -1) {
- perror("connect");
- goto bail;
- }
-
- size = sizeof(addr);
- if (getsockname(fd, (struct sockaddr*) &addr, &size) == -1) {
- perror("getsockname");
- goto bail;
- }
-
- ftp->localaddr = addr.sin_addr;
- ftp->fd = fd;
-
- if (!ftp_getresp(ftp) || ftp->resp != 220) {
- goto bail;
- }
-
- return ftp;
-
-bail:
- if (fd != -1)
- close(fd);
- free(ftp);
- return NULL;
-}
-
-
-ftpbuf_t*
-ftp_close(ftpbuf_t *ftp)
-{
- if (ftp == NULL)
- return NULL;
- if (ftp->fd)
- close(ftp->fd);
- ftp_gc(ftp);
- free(ftp);
- return NULL;
-}
-
-
-void
-ftp_gc(ftpbuf_t *ftp)
-{
- if (ftp == NULL)
- return;
-
- free(ftp->pwd);
- ftp->pwd = NULL;
- free(ftp->syst);
- ftp->syst = NULL;
-}
-
-
-int
-ftp_quit(ftpbuf_t *ftp)
-{
- if (ftp == NULL)
- return 0;
-
- if (!ftp_putcmd(ftp, "QUIT", NULL))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 221)
- return 0;
-
- free(ftp->pwd);
- ftp->pwd = NULL;
-
- return 1;
-}
-
-
-int
-ftp_login(ftpbuf_t *ftp, const char *user, const char *pass)
-{
- if (ftp == NULL)
- return 0;
-
- if (!ftp_putcmd(ftp, "USER", user))
- return 0;
- if (!ftp_getresp(ftp))
- return 0;
- if (ftp->resp == 230)
- return 1;
- if (ftp->resp != 331)
- return 0;
- if (!ftp_putcmd(ftp, "PASS", pass))
- return 0;
- if (!ftp_getresp(ftp))
- return 0;
- return (ftp->resp == 230);
-}
-
-
-int
-ftp_reinit(ftpbuf_t *ftp)
-{
- if (ftp == NULL)
- return 0;
-
- ftp_gc(ftp);
-
- if (!ftp_putcmd(ftp, "REIN", NULL))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 220)
- return 0;
-
- return 1;
-}
-
-
-const char*
-ftp_syst(ftpbuf_t *ftp)
-{
- char *syst, *end;
-
- if (ftp == NULL)
- return NULL;
-
- /* default to cached value */
- if (ftp->syst)
- return ftp->syst;
-
- if (!ftp_putcmd(ftp, "SYST", NULL))
- return NULL;
- if (!ftp_getresp(ftp) || ftp->resp != 215)
- return NULL;
-
- syst = ftp->inbuf;
- if ((end = strchr(syst, ' ')))
- *end = 0;
- ftp->syst = strdup(syst);
- if (end)
- *end = ' ';
-
- return ftp->syst;
-}
-
-
-const char*
-ftp_pwd(ftpbuf_t *ftp)
-{
- char *pwd, *end;
-
- if (ftp == NULL)
- return NULL;
-
- /* default to cached value */
- if (ftp->pwd)
- return ftp->pwd;
-
- if (!ftp_putcmd(ftp, "PWD", NULL))
- return NULL;
- if (!ftp_getresp(ftp) || ftp->resp != 257)
- return NULL;
-
- /* copy out the pwd from response */
- if ((pwd = strchr(ftp->inbuf, '"')) == NULL)
- return NULL;
- end = strrchr(++pwd, '"');
- *end = 0;
- ftp->pwd = strdup(pwd);
- *end = '"';
-
- return ftp->pwd;
-}
-
-
-int
-ftp_chdir(ftpbuf_t *ftp, const char *dir)
-{
- if (ftp == NULL)
- return 0;
-
- free(ftp->pwd);
- ftp->pwd = NULL;
-
- if (!ftp_putcmd(ftp, "CWD", dir))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 250)
- return 0;
-
- return 1;
-}
-
-
-int
-ftp_cdup(ftpbuf_t *ftp)
-{
- if (ftp == NULL)
- return 0;
-
- free(ftp->pwd);
- ftp->pwd = NULL;
-
- if (!ftp_putcmd(ftp, "CDUP", NULL))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 250)
- return 0;
-
- return 1;
-}
-
-
-char*
-ftp_mkdir(ftpbuf_t *ftp, const char *dir)
-{
- char *mkd, *end;
-
- if (ftp == NULL)
- return NULL;
-
- if (!ftp_putcmd(ftp, "MKD", dir))
- return NULL;
- if (!ftp_getresp(ftp) || ftp->resp != 257)
- return NULL;
-
- /* copy out the dir from response */
- if ((mkd = strchr(ftp->inbuf, '"')) == NULL)
- return NULL;
- end = strrchr(++mkd, '"');
- *end = 0;
- mkd = strdup(mkd);
- *end = '"';
-
- return mkd;
-}
-
-
-int
-ftp_rmdir(ftpbuf_t *ftp, const char *dir)
-{
- if (ftp == NULL)
- return 0;
-
- if (!ftp_putcmd(ftp, "RMD", dir))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 250)
- return 0;
-
- return 1;
-}
-
-
-char**
-ftp_nlist(ftpbuf_t *ftp, const char *path)
-{
- return ftp_genlist(ftp, "NLST", path);
-}
-
-
-char**
-ftp_list(ftpbuf_t *ftp, const char *path)
-{
- return ftp_genlist(ftp, "LIST", path);
-}
-
-
-int
-ftp_type(ftpbuf_t *ftp, ftptype_t type)
-{
- char typechar[2] = "?";
-
- if (ftp == NULL)
- return 0;
-
- if (type == ftp->type)
- return 1;
-
- if (type == FTPTYPE_ASCII)
- typechar[0] = 'A';
- else if (type == FTPTYPE_IMAGE)
- typechar[0] = 'I';
- else
- return 0;
-
- if (!ftp_putcmd(ftp, "TYPE", typechar))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 200)
- return 0;
-
- ftp->type = type;
-
- return 1;
-}
-
-
-int
-ftp_pasv(ftpbuf_t *ftp, int pasv)
-{
- char *ptr;
- union ipbox ipbox;
- unsigned long b[6];
- int n;
-
- if (ftp == NULL)
- return 0;
-
- if (pasv && ftp->pasv == 2)
- return 1;
-
- ftp->pasv = 0;
- if (!pasv)
- return 1;
-
- if (!ftp_putcmd(ftp, "PASV", NULL))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 227)
- return 0;
-
- /* parse out the IP and port */
- for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++);
- n = sscanf(ptr, "%lu,%lu,%lu,%lu,%lu,%lu",
- &b[0], &b[1], &b[2], &b[3], &b[4], &b[5]);
- if (n != 6)
- return 0;
-
- for (n=0; n<6; n++)
- ipbox.c[n] = b[n];
-
- memset(&ftp->pasvaddr, 0, sizeof(ftp->pasvaddr));
- ftp->pasvaddr.sin_family = AF_INET;
- ftp->pasvaddr.sin_addr.s_addr = ipbox.l[0];
- ftp->pasvaddr.sin_port = ipbox.s[2];
-
- ftp->pasv = 2;
-
- return 1;
-}
-
-
-int
-ftp_get(ftpbuf_t *ftp, FILE *outfp, const char *path, ftptype_t type)
-{
- databuf_t *data = NULL;
- char *ptr;
- int lastch;
- int rcvd;
-
- if (ftp == NULL)
- return 0;
-
- if (!ftp_type(ftp, type))
- goto bail;
-
- if ((data = ftp_getdata(ftp)) == NULL)
- goto bail;
-
- if (!ftp_putcmd(ftp, "RETR", path))
- goto bail;
- if (!ftp_getresp(ftp) || ftp->resp != 150)
- goto bail;
-
- if ((data = data_accept(data)) == NULL)
- goto bail;
-
- lastch = 0;
- while ((rcvd = my_recv(data->fd, data->buf, FTP_BUFSIZE))) {
- if (rcvd == -1)
- goto bail;
-
- if (type == FTPTYPE_ASCII) {
- for (ptr = data->buf; rcvd; rcvd--, ptr++) {
- if (lastch == '\r' && *ptr != '\n')
- putc('\r', outfp);
- if (*ptr != '\r')
- putc(*ptr, outfp);
- lastch = *ptr;
- }
- }
- else {
- fwrite(data->buf, rcvd, 1, outfp);
- }
- }
-
- if (type == FTPTYPE_ASCII && lastch == '\r')
- putc('\r', outfp);
-
- data = data_close(data);
-
- if (ferror(outfp))
- goto bail;
-
- if (!ftp_getresp(ftp) || ftp->resp != 226)
- goto bail;
-
- return 1;
-bail:
- data_close(data);
- return 0;
-}
-
-
-int
-ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, ftptype_t type)
-{
- databuf_t *data = NULL;
- int size;
- char *ptr;
- int ch;
-
- if (ftp == NULL)
- return 0;
-
- if (!ftp_type(ftp, type))
- goto bail;
-
- if ((data = ftp_getdata(ftp)) == NULL)
- goto bail;
-
- if (!ftp_putcmd(ftp, "STOR", path))
- goto bail;
- if (!ftp_getresp(ftp) || ftp->resp != 150)
- goto bail;
-
- if ((data = data_accept(data)) == NULL)
- goto bail;
-
- size = 0;
- ptr = data->buf;
- while ((ch = getc(infp)) != EOF) {
- /* flush if necessary */
- if (FTP_BUFSIZE - size < 2) {
- if (my_send(data->fd, data->buf, size) != size)
- goto bail;
- ptr = data->buf;
- size = 0;
- }
-
- if (ch == '\n' && type == FTPTYPE_ASCII) {
- *ptr++ = '\r';
- size++;
- }
-
- *ptr++ = ch;
- size++;
- }
-
- if (size && my_send(data->fd, data->buf, size) != size)
- goto bail;
-
- if (ferror(infp))
- goto bail;
-
- data = data_close(data);
-
- if (!ftp_getresp(ftp) || ftp->resp != 226)
- goto bail;
-
- return 1;
-bail:
- data_close(data);
- return 0;
-}
-
-
-int
-ftp_size(ftpbuf_t *ftp, const char *path)
-{
- if (ftp == NULL)
- return -1;
-
- if (!ftp_putcmd(ftp, "SIZE", path))
- return -1;
- if (!ftp_getresp(ftp) || ftp->resp != 213)
- return -1;
-
- return atoi(ftp->inbuf);
-}
-
-
-time_t
-ftp_mdtm(ftpbuf_t *ftp, const char *path)
-{
- time_t stamp;
- struct tm *gmt, tmbuf;
- struct tm tm;
- char *ptr;
- int n;
-
- if (ftp == NULL)
- return -1;
-
- if (!ftp_putcmd(ftp, "MDTM", path))
- return -1;
- if (!ftp_getresp(ftp) || ftp->resp != 213)
- return -1;
-
- /* parse out the timestamp */
- for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++);
- n = sscanf(ptr, "%4u%2u%2u%2u%2u%2u",
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
- &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
- if (n != 6)
- return -1;
- tm.tm_year -= 1900;
- tm.tm_mon--;
- tm.tm_isdst = -1;
-
- /* figure out the GMT offset */
- stamp = time(NULL);
- gmt = gmtime_r(&stamp, &tmbuf);
- gmt->tm_isdst = -1;
-
- /* apply the GMT offset */
- tm.tm_sec += stamp - mktime(gmt);
- tm.tm_isdst = gmt->tm_isdst;
-
- stamp = mktime(&tm);
-
- return stamp;
-}
-
-
-int
-ftp_delete(ftpbuf_t *ftp, const char *path)
-{
- if (ftp == NULL)
- return 0;
-
- if (!ftp_putcmd(ftp, "DELE", path))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 250)
- return 0;
-
- return 1;
-}
-
-
-int
-ftp_rename(ftpbuf_t *ftp, const char *src, const char *dest)
-{
- if (ftp == NULL)
- return 0;
-
- if (!ftp_putcmd(ftp, "RNFR", src))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 350)
- return 0;
-
- if (!ftp_putcmd(ftp, "RNTO", dest))
- return 0;
- if (!ftp_getresp(ftp) || ftp->resp != 250)
- return 0;
-
- return 1;
-}
-
-/* static functions */
-
-int
-ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args)
-{
- int size;
- char *data;
-
- /* build the output buffer */
- if (args) {
- /* "cmd args\r\n\0" */
- if (strlen(cmd) + strlen(args) + 4 > FTP_BUFSIZE)
- return 0;
- size = sprintf(ftp->outbuf, "%s %s\r\n", cmd, args);
- }
- else {
- /* "cmd\r\n\0" */
- if (strlen(cmd) + 3 > FTP_BUFSIZE)
- return 0;
- size = sprintf(ftp->outbuf, "%s\r\n", cmd);
- }
-
- data = ftp->outbuf;
- if (my_send(ftp->fd, data, size) != size)
- return 0;
-
- return 1;
-}
-
-
-int
-ftp_readline(ftpbuf_t *ftp)
-{
- int size, rcvd;
- char *data, *eol;
-
- /* shift the extra to the front */
- size = FTP_BUFSIZE;
- rcvd = 0;
- if (ftp->extra) {
- memmove(ftp->inbuf, ftp->extra, ftp->extralen);
- rcvd = ftp->extralen;
- }
-
- data = ftp->inbuf;
-
- do {
- size -= rcvd;
- for (eol = data; rcvd; rcvd--, eol++) {
- if (*eol == '\r') {
- *eol = 0;
- ftp->extra = eol + 1;
- if (rcvd > 1 && *(eol + 1) == '\n') {
- ftp->extra++;
- rcvd--;
- }
- if ((ftp->extralen = --rcvd) == 0)
- ftp->extra = NULL;
- return 1;
- }
- else if (*eol == '\n') {
- *eol = 0;
- ftp->extra = eol + 1;
- if ((ftp->extralen = --rcvd) == 0)
- ftp->extra = NULL;
- return 1;
- }
- }
-
- data = eol;
- if ((rcvd = my_recv(ftp->fd, data, size)) < 1)
- return 0;
- } while (size);
-
- return 0;
-}
-
-
-int
-ftp_getresp(ftpbuf_t *ftp)
-{
- char *buf;
-
- if (ftp == NULL)
- return 0;
- buf = ftp->inbuf;
- ftp->resp = 0;
-
-
- while (1) {
- if (!ftp_readline(ftp))
- return 0;
- if (ftp->inbuf[3] == '-')
- continue;
- else if (ftp->inbuf[3] != ' ')
- return 0;
- break;
- }
-
- /* translate the tag */
- if ( !isdigit(ftp->inbuf[0]) ||
- !isdigit(ftp->inbuf[1]) ||
- !isdigit(ftp->inbuf[2]))
- {
- return 0;
- }
-
- ftp->resp = 100 * (ftp->inbuf[0] - '0') +
- 10 * (ftp->inbuf[1] - '0') +
- (ftp->inbuf[2] - '0');
-
- memmove(ftp->inbuf, ftp->inbuf + 4, FTP_BUFSIZE - 4);
-
- return 1;
-}
-
-
-int
-my_send(int s, void *buf, size_t len)
-{
- fd_set write_set;
- struct timeval tv;
- int n, size, sent;
-
- size = len;
- while (size) {
- tv.tv_sec = FTP_TIMEOUT;
- tv.tv_usec = 0;
-
- FD_ZERO(&write_set);
- FD_SET(s, &write_set);
- n = select(s + 1, NULL, &write_set, NULL, &tv);
- if (n < 1) {
- if (n == 0)
- errno = ETIMEDOUT;
- return -1;
- }
-
- sent = send(s, buf, size, 0);
- if (sent == -1)
- return -1;
-
- buf = (char*) buf + sent;
- size -= sent;
- }
-
- return len;
-}
-
-
-int
-my_recv(int s, void *buf, size_t len)
-{
- fd_set read_set;
- struct timeval tv;
- int n;
-
- tv.tv_sec = FTP_TIMEOUT;
- tv.tv_usec = 0;
-
- FD_ZERO(&read_set);
- FD_SET(s, &read_set);
- n = select(s + 1, &read_set, NULL, NULL, &tv);
- if (n < 1) {
- if (n == 0)
- errno = ETIMEDOUT;
- return -1;
- }
-
- return recv(s, buf, len, 0);
-}
-
-
-int
-my_connect(int s, const struct sockaddr *addr, int addrlen)
-{
- fd_set conn_set;
- int flags;
- int n;
- int error = 0;
- struct timeval tv;
-
- flags = fcntl(s, F_GETFL, 0);
- fcntl(s, F_SETFL, flags | O_NONBLOCK);
-
- n = connect(s, addr, addrlen);
- if (n == -1 && errno != EINPROGRESS)
- return -1;
-
- if (n) {
- FD_ZERO(&conn_set);
- FD_SET(s, &conn_set);
-
- tv.tv_sec = FTP_TIMEOUT;
- tv.tv_usec = 0;
-
- n = select(s + 1, &conn_set, &conn_set, NULL, &tv);
- if (n < 1) {
- if (n == 0)
- errno = ETIMEDOUT;
- return -1;
- }
-
- if (FD_ISSET(s, &conn_set)) {
- n = sizeof(error);
- n = getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &n);
- if (n == -1 || error) {
- if (error)
- errno = error;
- return -1;
- }
- }
- }
-
- fcntl(s, F_SETFL, flags);
-
- return 0;
-}
-
-
-int
-my_accept(int s, struct sockaddr *addr, int *addrlen)
-{
- fd_set accept_set;
- struct timeval tv;
- int n;
-
- tv.tv_sec = FTP_TIMEOUT;
- tv.tv_usec = 0;
- FD_ZERO(&accept_set);
- FD_SET(s, &accept_set);
-
- n = select(s + 1, &accept_set, NULL, NULL, &tv);
- if (n < 1) {
- if (n == 0)
- errno = ETIMEDOUT;
- return -1;
- }
-
- return accept(s, addr, addrlen);
-}
-
-
-databuf_t*
-ftp_getdata(ftpbuf_t *ftp)
-{
- int fd = -1;
- databuf_t *data;
- struct sockaddr_in addr;
- int size;
- union ipbox ipbox;
- char arg[sizeof("255,255,255,255,255,255")];
-
-
- /* ask for a passive connection if we need one */
- if (ftp->pasv && !ftp_pasv(ftp, 1))
- return NULL;
-
- /* alloc the data structure */
- data = calloc(1, sizeof(*data));
- if (data == NULL) {
- perror("calloc");
- return NULL;
- }
- data->listener = -1;
- data->fd = -1;
- data->type = ftp->type;
-
- /* bind/listen */
- if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
- perror("socket");
- goto bail;
- }
-
- /* passive connection handler */
- if (ftp->pasv) {
- /* clear the ready status */
- ftp->pasv = 1;
-
- /* connect */
- if (my_connect(fd, (struct sockaddr*) &ftp->pasvaddr,
- sizeof(ftp->pasvaddr)) == -1)
- {
- perror("connect");
- close(fd);
- free(data);
- return NULL;
- }
-
- data->fd = fd;
-
- return data;
- }
-
-
- /* active (normal) connection */
-
- /* bind to a local address */
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = INADDR_ANY;
- addr.sin_port = 0;
-
- if (bind(fd, (struct sockaddr*) &addr, sizeof(addr)) == -1) {
- perror("bind");
- goto bail;
- }
-
- size = sizeof(addr);
- if (getsockname(fd, (struct sockaddr*) &addr, &size) == -1) {
- perror("getsockname");
- goto bail;
- }
-
- if (listen(fd, 5) == -1) {
- perror("listen");
- goto bail;
- }
-
- data->listener = fd;
-
- /* send the PORT */
- ipbox.l[0] = ftp->localaddr.s_addr;
- ipbox.s[2] = addr.sin_port;
- sprintf(arg, "%u,%u,%u,%u,%u,%u",
- ipbox.c[0], ipbox.c[1], ipbox.c[2], ipbox.c[3],
- ipbox.c[4], ipbox.c[5]);
-
- if (!ftp_putcmd(ftp, "PORT", arg))
- goto bail;
- if (!ftp_getresp(ftp) || ftp->resp != 200)
- goto bail;
-
- return data;
-
-bail:
- if (fd != -1)
- close(fd);
- free(data);
- return NULL;
-}
-
-
-databuf_t*
-data_accept(databuf_t *data)
-{
- struct sockaddr_in addr;
- int size;
-
- if (data->fd != -1)
- return data;
-
- size = sizeof(addr);
- data->fd = my_accept(data->listener, (struct sockaddr*) &addr, &size);
- close(data->listener);
- data->listener = -1;
-
- if (data->fd == -1) {
- free(data);
- return NULL;
- }
-
- return data;
-}
-
-
-databuf_t*
-data_close(databuf_t *data)
-{
- if (data == NULL)
- return NULL;
- if (data->listener != -1)
- close(data->listener);
- if (data->fd != -1)
- close(data->fd);
- free(data);
- return NULL;
-}
-
-
-char**
-ftp_genlist(ftpbuf_t *ftp, const char *cmd, const char *path)
-{
- FILE *tmpfp = NULL;
- databuf_t *data = NULL;
- char *ptr;
- int ch, lastch;
- int size, rcvd;
- int lines;
- char **ret = NULL;
- char **entry;
- char *text;
-
-
- if ((tmpfp = tmpfile()) == NULL)
- return NULL;
-
- if (!ftp_type(ftp, FTPTYPE_ASCII))
- goto bail;
-
- if ((data = ftp_getdata(ftp)) == NULL)
- goto bail;
-
- if (!ftp_putcmd(ftp, cmd, path))
- goto bail;
- if (!ftp_getresp(ftp) || ftp->resp != 150)
- goto bail;
-
- /* pull data buffer into tmpfile */
- if ((data = data_accept(data)) == NULL)
- goto bail;
-
- size = 0;
- lines = 0;
- lastch = 0;
- while ((rcvd = my_recv(data->fd, data->buf, FTP_BUFSIZE))) {
- if (rcvd == -1)
- goto bail;
-
- fwrite(data->buf, rcvd, 1, tmpfp);
-
- size += rcvd;
- for (ptr = data->buf; rcvd; rcvd--, ptr++) {
- if (*ptr == '\n' && lastch == '\r')
- lines++;
- else
- size++;
- lastch = *ptr;
- }
- }
-
- data = data_close(data);
-
- if (ferror(tmpfp))
- goto bail;
-
-
-
- rewind(tmpfp);
-
- ret = malloc((lines + 1) * sizeof(char**) + size * sizeof(char*));
- if (ret == NULL) {
- perror("malloc");
- goto bail;
- }
-
- entry = ret;
- text = (char*) (ret + lines + 1);
- *entry = text;
- lastch = 0;
- while ((ch = getc(tmpfp)) != EOF) {
- if (ch == '\n' && lastch == '\r') {
- *(text - 1) = 0;
- *++entry = text;
- }
- else {
- *text++ = ch;
- }
- lastch = ch;
- }
- *entry = NULL;
-
- if (ferror(tmpfp))
- goto bail;
-
- fclose(tmpfp);
-
- if (!ftp_getresp(ftp) || ftp->resp != 226) {
- free(ret);
- return NULL;
- }
-
- return ret;
-bail:
- data_close(data);
- fclose(tmpfp);
- free(ret);
- return NULL;
-}
-
-#endif /* HAVE_FTP */
diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h
deleted file mode 100644
index b202981d9a..0000000000
--- a/ext/ftp/ftp.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP HTML Embedded Scripting Language Version 3.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
- +----------------------------------------------------------------------+
- | This program is free software; you can redistribute it and/or modify |
- | it under the terms of one of the following licenses: |
- | |
- | A) the GNU General Public License as published by the Free Software |
- | Foundation; either version 2 of the License, or (at your option) |
- | any later version. |
- | |
- | B) the PHP License as published by the PHP Development Team and |
- | included in the distribution in the file: LICENSE |
- | |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU General Public License for more details. |
- | |
- | You should have received a copy of both licenses referred to here. |
- | If you did not, or have any questions about PHP licensing, please |
- | contact core@php.net. |
- +----------------------------------------------------------------------+
- | Authors: |
- | Andrew Skalski <askalski@chek.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#ifndef _FTP_H
-#define _FTP_H
-
-#include <stdio.h>
-#include <netinet/in.h>
-
-
-/* XXX these should be configurable at runtime XXX */
-#define FTP_BUFSIZE 4096
-#define FTP_TIMEOUT 90
-
-typedef enum ftptype {
- FTPTYPE_ASCII,
- FTPTYPE_IMAGE,
-} ftptype_t;
-
-typedef struct ftpbuf
-{
- int fd; /* control connection */
- struct in_addr localaddr; /* local inet address */
- int resp; /* last response code */
- char inbuf[FTP_BUFSIZE]; /* last response text */
- char *extra; /* extra characters */
- int extralen; /* number of extra chars */
- char outbuf[FTP_BUFSIZE]; /* command output buffer */
- char *pwd; /* cached pwd */
- char *syst; /* cached system type */
- ftptype_t type; /* current transfer type */
- int pasv; /* 0=off; 1=pasv; 2=ready */
- struct sockaddr_in pasvaddr; /* passive mode address */
-} ftpbuf_t;
-
-typedef struct databuf
-{
- int listener; /* listener socket */
- int fd; /* data connection */
- ftptype_t type; /* transfer type */
- char buf[FTP_BUFSIZE]; /* data buffer */
-} databuf_t;
-
-
-/* open a FTP connection, returns ftpbuf (NULL on error)
- * port is the ftp port in network byte order, or 0 for the default
- */
-ftpbuf_t* ftp_open(const char *host, short port);
-
-/* 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 */
-int ftp_login(ftpbuf_t *ftp, const char *user, const char *pass);
-
-/* 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);
-
-/* 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);
-
-/* 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);
-
-/* removes a directory, return true on success, false on error */
-int ftp_rmdir(ftpbuf_t *ftp, const char *dir);
-
-/* 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)
- */
-char** ftp_nlist(ftpbuf_t *ftp, const char *path);
-
-/* 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)
- */
-char** ftp_list(ftpbuf_t *ftp, const char *path);
-
-/* switches passive mode on or off
- * returns true on success, false on error
- */
-int ftp_pasv(ftpbuf_t *ftp, int pasv);
-
-/* retrieves a file and saves its contents to outfp
- * returns true on success, false on error
- */
-int ftp_get(ftpbuf_t *ftp, FILE *outfp, const char *path,
- ftptype_t type);
-
-/* stores the data from infp as a file on the remote server
- * returns true on success, false on error
- */
-int ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp,
- ftptype_t type);
-
-/* returns the size of the given file, or -1 on error */
-int ftp_size(ftpbuf_t *ftp, const char *path);
-
-/* returns the last modified time of the given file, or -1 on error */
-time_t ftp_mdtm(ftpbuf_t *ftp, const char *path);
-
-/* 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);
-
-#endif
diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c
deleted file mode 100644
index 7bd7f4b495..0000000000
--- a/ext/ftp/php_ftp.c
+++ /dev/null
@@ -1,796 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP HTML Embedded Scripting Language Version 3.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
- +----------------------------------------------------------------------+
- | This program is free software; you can redistribute it and/or modify |
- | it under the terms of one of the following licenses: |
- | |
- | A) the GNU General Public License as published by the Free Software |
- | Foundation; either version 2 of the License, or (at your option) |
- | any later version. |
- | |
- | B) the PHP License as published by the PHP Development Team and |
- | included in the distribution in the file: LICENSE |
- | |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU General Public License for more details. |
- | |
- | You should have received a copy of both licenses referred to here. |
- | If you did not, or have any questions about PHP licensing, please |
- | contact core@php.net. |
- +----------------------------------------------------------------------+
- | Authors: |
- | Andrew Skalski <askalski@chek.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-
-#if HAVE_FTP
-
-#ifndef ZEND_VERSION
-#include "internal_functions.h"
-#include "php3_list.h"
-#define php_error php3_error
-#endif
-
-#include "ext/standard/file.h"
-
-#include "php_ftp.h"
-#include "ftp.h"
-
-static int le_ftpbuf;
-
-
-function_entry php3_ftp_functions[] = {
- PHP_FE(ftp_connect, NULL)
- PHP_FE(ftp_login, NULL)
- PHP_FE(ftp_pwd, NULL)
- PHP_FE(ftp_cdup, NULL)
- PHP_FE(ftp_chdir, NULL)
- PHP_FE(ftp_mkdir, NULL)
- PHP_FE(ftp_rmdir, NULL)
- PHP_FE(ftp_nlist, NULL)
- PHP_FE(ftp_rawlist, NULL)
- PHP_FE(ftp_systype, NULL)
- PHP_FE(ftp_pasv, NULL)
- PHP_FE(ftp_get, NULL)
- PHP_FE(ftp_fget, NULL)
- PHP_FE(ftp_put, NULL)
- PHP_FE(ftp_fput, NULL)
- PHP_FE(ftp_size, NULL)
- PHP_FE(ftp_mdtm, NULL)
- PHP_FE(ftp_rename, NULL)
- PHP_FE(ftp_delete, NULL)
- PHP_FE(ftp_quit, NULL)
- {NULL, NULL, NULL}
-};
-
-php3_module_entry php3_ftp_module_entry = {
- "FTP Functions",
- php3_ftp_functions,
-#ifdef ZEND_VERSION
- PHP_MINIT(ftp),
-#else
- php3_minit_ftp,
-#endif
- NULL,
- NULL,
- NULL,
- NULL,
- STANDARD_MODULE_PROPERTIES
-};
-
-static void ftp_destructor_ftpbuf(ftpbuf_t *ftp)
-{
- ftp_close(ftp);
-}
-
-#ifndef ZEND_VERSION
-int php3_minit_ftp(INIT_FUNC_ARGS)
-#else
-PHP_MINIT_FUNCTION(ftp)
-#endif
-{
-
- ELS_FETCH();
-
- le_ftpbuf = register_list_destructors(ftp_destructor_ftpbuf, NULL);
- REGISTER_MAIN_LONG_CONSTANT("FTP_ASCII", FTPTYPE_ASCII,
- CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("FTP_BINARY", FTPTYPE_IMAGE,
- CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("FTP_IMAGE", FTPTYPE_IMAGE,
- CONST_PERSISTENT | CONST_CS);
- REGISTER_MAIN_LONG_CONSTANT("FTP_TEXT", FTPTYPE_ASCII,
- CONST_PERSISTENT | CONST_CS);
- return SUCCESS;
-}
-
-
-#define FTPBUF(ftp, pval) { \
- int id, type; \
- convert_to_long(pval); \
- id = (pval)->value.lval; \
- (ftp) = php3_list_find(id, &type); \
- if (!(ftp) || type != le_ftpbuf) { \
- php_error(E_WARNING, "Unable to find ftpbuf %d", id); \
- RETURN_FALSE; \
- } \
- }
-
-#define XTYPE(xtype, pval) { \
- convert_to_long(pval); \
- if ( pval->value.lval != FTPTYPE_ASCII && \
- pval->value.lval != FTPTYPE_IMAGE) \
- { \
- php_error(E_WARNING, "arg4 must be FTP_ASCII or FTP_IMAGE"); \
- RETURN_FALSE; \
- } \
- (xtype) = pval->value.lval; \
- }
-
-#define FILEP(fp, pval) { \
- ZEND_FETCH_RESOURCE(fp, FILE *, &pval, -1, "File-Handle", php_file_le_fopen()); \
- }
-
-/* {{{ proto int ftp_connect(string host [, int port])
- Open a FTP stream */
-PHP_FUNCTION(ftp_connect)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
- short port = 0;
-
- /* arg1 - hostname
- * arg2 - [port]
- */
- switch (ARG_COUNT(ht)) {
- case 1:
- if (getParameters(ht, 1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- case 2:
- if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long(arg2);
- port = arg2->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string(arg1);
-
- /* connect */
- ftp = ftp_open(arg1->value.str.val, htons(port));
- if (ftp == NULL)
- RETURN_FALSE;
-
- RETURN_LONG(php3_list_insert(ftp, le_ftpbuf));
-}
-/* }}} */
-
-/* {{{ proto int ftp_login(int stream, string username, string password)
- Logs into the FTP server. */
-PHP_FUNCTION(ftp_login)
-{
- pval *arg1, *arg2, *arg3;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - username
- * arg3 - password
- */
- if ( ARG_COUNT(ht) != 3 ||
- getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string(arg2);
- convert_to_string(arg3);
-
- FTPBUF(ftp, arg1);
-
- /* log in */
- if (!ftp_login(ftp, arg2->value.str.val, arg3->value.str.val)) {
- php_error(E_WARNING, "ftp_login: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto string ftp_pwd(int stream)
- Returns the present working directory. */
-PHP_FUNCTION(ftp_pwd)
-{
- pval *arg1;
- ftpbuf_t *ftp;
- const char *pwd;
-
- /* arg1 - ftp
- */
- if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
-
- pwd = ftp_pwd(ftp);
- if (pwd == NULL) {
- php_error(E_WARNING, "ftp_pwd: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_STRING((char*) pwd, 1);
-}
-/* }}} */
-
-/* {{{ proto int ftp_cdup(int stream)
- Changes to the parent directory */
-PHP_FUNCTION(ftp_cdup)
-{
- pval *arg1;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- */
- if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
-
- if (!ftp_cdup(ftp)) {
- php_error(E_WARNING, "ftp_cdup: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_chdir(int stream, string directory)
- Changes directories */
-PHP_FUNCTION(ftp_chdir)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - directory
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string(arg2);
-
- FTPBUF(ftp, arg1);
-
- /* change directories */
- if (!ftp_chdir(ftp, arg2->value.str.val)) {
- php_error(E_WARNING, "ftp_chdir: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto string ftp_mkdir(int stream, string directory)
- Creates a directory */
-PHP_FUNCTION(ftp_mkdir)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
- char *ret, *tmp;
-
- /* arg1 - ftp
- * arg2 - directory
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string(arg2);
-
- FTPBUF(ftp, arg1);
-
- /* change directories */
- tmp = ftp_mkdir(ftp, arg2->value.str.val);
- if (tmp == NULL) {
- php_error(E_WARNING, "ftp_mkdir: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- if ((ret = estrdup(tmp)) == NULL) {
- free(tmp);
- php_error(E_WARNING, "estrdup failed");
- RETURN_FALSE;
- }
-
- RETURN_STRING(ret, 0);
-}
-/* }}} */
-
-/* {{{ proto int ftp_rmdir(int stream, string directory)
- Removes a directory */
-PHP_FUNCTION(ftp_rmdir)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - directory
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string(arg2);
-
- FTPBUF(ftp, arg1);
-
- /* change directories */
- if (!ftp_rmdir(ftp, arg2->value.str.val)) {
- php_error(E_WARNING, "ftp_rmdir: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto array ftp_nlist(int stream, string directory)
- Returns an array of filenames in the given directory */
-PHP_FUNCTION(ftp_nlist)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
- char **nlist, **ptr;
-
- /* arg1 - ftp
- * arg2 - directory
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string(arg2);
-
- FTPBUF(ftp, arg1);
-
- /* get list of files */
- nlist = ftp_nlist(ftp, arg2->value.str.val);
- if (nlist == NULL) {
- RETURN_FALSE;
- }
-
- array_init(return_value);
- for (ptr = nlist; *ptr; ptr++)
- add_next_index_string(return_value, *ptr, 1);
- free(nlist);
-}
-/* }}} */
-
-/* {{{ proto array ftp_rawlist(int stream, string directory)
- Returns a detailed listing of a directory as an array of output lines */
-PHP_FUNCTION(ftp_rawlist)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
- char **llist, **ptr;
-
- /* arg1 - ftp
- * arg2 - directory
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string(arg2);
-
- FTPBUF(ftp, arg1);
-
- /* get directory listing */
- llist = ftp_list(ftp, arg2->value.str.val);
- if (llist == NULL) {
- RETURN_FALSE;
- }
-
- array_init(return_value);
- for (ptr = llist; *ptr; ptr++)
- add_next_index_string(return_value, *ptr, 1);
- free(llist);
-}
-/* }}} */
-
-/* {{{ proto string ftp_systype(int stream)
- Returns the system type identifier */
-PHP_FUNCTION(ftp_systype)
-{
- pval *arg1;
- ftpbuf_t *ftp;
- const char *syst;
-
-
- /* arg1 - ftp
- * arg2 - directory
- */
- if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
-
- syst = ftp_syst(ftp);
- if (syst == NULL) {
- php_error(E_WARNING, "ftp_syst: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_STRING((char*) syst, 1);
-}
-/* }}} */
-
-/* {{{ proto int ftp_fget(int stream, int fp, string remote_file, int mode)
- Retrieves a file from the FTP server and writes it to an open file. */
-PHP_FUNCTION(ftp_fget)
-{
- pval *arg1, *arg2, *arg3, *arg4;
- ftpbuf_t *ftp;
- ftptype_t xtype;
- FILE *fp;
-
- /* arg1 - ftp
- * arg2 - fp
- * arg3 - remote file
- * arg4 - transfer mode
- */
- if ( ARG_COUNT(ht) != 4 ||
- getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- FILEP(fp, arg2);
- convert_to_string(arg3);
- XTYPE(xtype, arg4);
-
- if (!ftp_get(ftp, fp, arg3->value.str.val, xtype) || ferror(fp)) {
- php_error(E_WARNING, "ftp_get: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- if (ferror(fp)) {
- php_error(E_WARNING, "error writing %s", arg2->value.str.val);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_pasv(int stream, int pasv)
- Turns passive mode on or off. */
-PHP_FUNCTION(ftp_pasv)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - pasv
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_long(arg2);
-
- if (!ftp_pasv(ftp, (arg2->value.lval) ? 1 : 0))
- RETURN_FALSE;
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_get(int stream, string local_file, string remote_file, int mode)
- Retrieves a file from the FTP server and writes it to a local file. */
-PHP_FUNCTION(ftp_get)
-{
- pval *arg1, *arg2, *arg3, *arg4;
- ftpbuf_t *ftp;
- ftptype_t xtype;
- FILE *outfp, *tmpfp;
- int ch;
-
-
- /* arg1 - ftp
- * arg2 - destination (local) file
- * arg3 - source (remote) file
- * arg4 - transfer mode
- */
- if ( ARG_COUNT(ht) != 4 ||
- getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_string(arg2);
- convert_to_string(arg3);
- XTYPE(xtype, arg4);
-
- /* get to temporary file, so if there is an error, no existing
- * file gets clobbered
- */
- if ((tmpfp = tmpfile()) == NULL) {
- php_error(E_WARNING, "error opening tmpfile");
- RETURN_FALSE;
- }
-
- if ( !ftp_get(ftp, tmpfp, arg3->value.str.val, xtype) ||
- ferror(tmpfp))
- {
- fclose(tmpfp);
- php_error(E_WARNING, "ftp_get: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- if ((outfp = fopen(arg2->value.str.val, "w")) == NULL) {
- fclose(tmpfp);
- php_error(E_WARNING, "error opening %s", arg2->value.str.val);
- RETURN_FALSE;
- }
-
- rewind(tmpfp);
- while ((ch = getc(tmpfp)) != EOF)
- putc(ch, outfp);
-
- if (ferror(tmpfp) || ferror(outfp)) {
- fclose(tmpfp);
- fclose(outfp);
- php_error(E_WARNING, "error writing %s", arg2->value.str.val);
- RETURN_FALSE;
- }
-
- fclose(tmpfp);
- fclose(outfp);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_fput(int stream, string local_file, string remote_file, int mode)
- Stores a file from an open file to the FTP server. */
-PHP_FUNCTION(ftp_fput)
-{
- pval *arg1, *arg2, *arg3, *arg4;
- ftpbuf_t *ftp;
- ftptype_t xtype;
- FILE *fp;
-
- /* arg1 - ftp
- * arg2 - remote file
- * arg3 - fp
- * arg4 - transfer mode
- */
- if ( ARG_COUNT(ht) != 4 ||
- getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_string(arg2);
- FILEP(fp, arg3);
- XTYPE(xtype, arg4);
-
- if (!ftp_put(ftp, arg2->value.str.val, fp, xtype)) {
- php_error(E_WARNING, "ftp_put: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_put(int stream, string remote_file, string local_file, int mode)
- Stores a file on the FTP server */
-PHP_FUNCTION(ftp_put)
-{
- pval *arg1, *arg2, *arg3, *arg4;
- ftpbuf_t *ftp;
- ftptype_t xtype;
- FILE *infp;
-
-
- /* arg1 - ftp
- * arg2 - destination (remote) file
- * arg3 - source (local) file
- * arg4 - transfer mode
- */
- if ( ARG_COUNT(ht) != 4 ||
- getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_string(arg2);
- convert_to_string(arg3);
- XTYPE(xtype, arg4);
-
- if ((infp = fopen(arg3->value.str.val, "r")) == NULL) {
- php_error(E_WARNING, "error opening %s", arg3->value.str.val);
- RETURN_FALSE;
- }
- if ( !ftp_put(ftp, arg2->value.str.val, infp, xtype) ||
- ferror(infp))
- {
- fclose(infp);
- php_error(E_WARNING, "ftp_put: %s", ftp->inbuf);
- RETURN_FALSE;
- }
- fclose(infp);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_size(int stream, string path)
- Returns the size of the file, or -1 on error. */
-PHP_FUNCTION(ftp_size)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - path
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_string(arg2);
-
- /* get file size */
- RETURN_LONG(ftp_size(ftp, arg2->value.str.val));
-}
-/* }}} */
-
-/* {{{ proto int ftp_mdtm(int stream, string path)
- Returns the last modification time of the file, or -1 on error */
-PHP_FUNCTION(ftp_mdtm)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - path
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_string(arg2);
-
- /* get file mod time */
- RETURN_LONG(ftp_mdtm(ftp, arg2->value.str.val));
-}
-/* }}} */
-
-/* {{{ proto int ftp_rename(int stream, string src, string dest)
- Renames the given file to a new path */
-PHP_FUNCTION(ftp_rename)
-{
- pval *arg1, *arg2, *arg3;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - src
- * arg3 - dest
- */
- if ( ARG_COUNT(ht) != 3 ||
- getParameters(ht, 3, &arg1, &arg2, &arg3) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_string(arg2);
- convert_to_string(arg3);
-
- /* rename the file */
- if (!ftp_rename(ftp, arg2->value.str.val, arg3->value.str.val)) {
- php_error(E_WARNING, "ftp_rename: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_delete(int stream, string path)
- Deletes a file */
-PHP_FUNCTION(ftp_delete)
-{
- pval *arg1, *arg2;
- ftpbuf_t *ftp;
-
- /* arg1 - ftp
- * arg2 - path
- */
- if ( ARG_COUNT(ht) != 2 ||
- getParameters(ht, 2, &arg1, &arg2) == FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
-
- FTPBUF(ftp, arg1);
- convert_to_string(arg2);
-
- /* delete the file */
- if (!ftp_delete(ftp, arg2->value.str.val)) {
- php_error(E_WARNING, "ftp_delete: %s", ftp->inbuf);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftp_quit(int stream)
- Closes the FTP stream */
-PHP_FUNCTION(ftp_quit)
-{
- pval *arg1;
- int id, type;
-
- /* arg1 - ftp
- */
- if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- id = arg1->value.lval;
- if (php3_list_find(id, &type) && type == le_ftpbuf)
- php3_list_delete(id);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-#endif /* HAVE_FTP */
diff --git a/ext/ftp/php_ftp.h b/ext/ftp/php_ftp.h
deleted file mode 100644
index 7da896cc8d..0000000000
--- a/ext/ftp/php_ftp.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP HTML Embedded Scripting Language Version 3.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
- +----------------------------------------------------------------------+
- | This program is free software; you can redistribute it and/or modify |
- | it under the terms of one of the following licenses: |
- | |
- | A) the GNU General Public License as published by the Free Software |
- | Foundation; either version 2 of the License, or (at your option) |
- | any later version. |
- | |
- | B) the PHP License as published by the PHP Development Team and |
- | included in the distribution in the file: LICENSE |
- | |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU General Public License for more details. |
- | |
- | You should have received a copy of both licenses referred to here. |
- | If you did not, or have any questions about PHP licensing, please |
- | contact core@php.net. |
- +----------------------------------------------------------------------+
- | Authors: |
- | Andrew Skalski <askalski@chek.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#ifndef _INCLUDED_FTP_H
-#define _INCLUDED_FTP_H
-
-#if COMPILE_DL
-#undef HAVE_FTP
-#define HAVE_FTP 1
-#endif
-
-#if HAVE_FTP
-
-extern php3_module_entry php3_ftp_module_entry;
-#define php3_ftp_module_ptr &php3_ftp_module_entry
-
-#ifdef ZEND_VERSION
-PHP_MINIT_FUNCTION(ftp);
-#else
-int php3_minit_ftp(INIT_FUNC_ARGS);
-#endif
-
-PHP_FUNCTION(ftp_connect);
-PHP_FUNCTION(ftp_login);
-PHP_FUNCTION(ftp_pwd);
-PHP_FUNCTION(ftp_cdup);
-PHP_FUNCTION(ftp_chdir);
-PHP_FUNCTION(ftp_mkdir);
-PHP_FUNCTION(ftp_rmdir);
-PHP_FUNCTION(ftp_nlist);
-PHP_FUNCTION(ftp_rawlist);
-PHP_FUNCTION(ftp_systype);
-PHP_FUNCTION(ftp_pasv);
-PHP_FUNCTION(ftp_get);
-PHP_FUNCTION(ftp_fget);
-PHP_FUNCTION(ftp_put);
-PHP_FUNCTION(ftp_fput);
-PHP_FUNCTION(ftp_size);
-PHP_FUNCTION(ftp_mdtm);
-PHP_FUNCTION(ftp_rename);
-PHP_FUNCTION(ftp_delete);
-PHP_FUNCTION(ftp_quit);
-
-#define phpext_ftp_ptr php3_ftp_module_ptr
-
-#else
-#define php3_ftp_module_ptr NULL
-#endif /* HAVE_FTP */
-
-#endif