]> granicus.if.org Git - php/commitdiff
@Added support for socket and popen file types to ftp_fput (Jason)
authorJason Greene <jason@php.net>
Tue, 17 Jul 2001 05:53:03 +0000 (05:53 +0000)
committerJason Greene <jason@php.net>
Tue, 17 Jul 2001 05:53:03 +0000 (05:53 +0000)
ext/ftp/ftp.c
ext/ftp/ftp.h
ext/ftp/php_ftp.c

index 602a5507f446a4d74c7dc144de6b8f39aa2098b8..f191378c524f7de2739695cb1d56581c4cba398b 100644 (file)
@@ -582,7 +582,7 @@ bail:
 /* {{{ ftp_put
  */
 int
-ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, ftptype_t type)
+ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, int insocket, int issock, ftptype_t type)
 {
        databuf_t               *data = NULL;
        int                     size;
@@ -608,7 +608,7 @@ ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, ftptype_t type)
 
        size = 0;
        ptr = data->buf;
-       while ((ch = getc(infp)) != EOF) {
+       while ((ch = FP_FGETC(insocket, infp, issock))!=EOF && !FP_FEOF(insocket, infp, issock)) {
                /* flush if necessary */
                if (FTP_BUFSIZE - size < 2) {
                        if (my_send(data->fd, data->buf, size) != size)
@@ -629,7 +629,7 @@ ftp_put(ftpbuf_t *ftp, const char *path, FILE *infp, ftptype_t type)
        if (size && my_send(data->fd, data->buf, size) != size)
                goto bail;
 
-       if (ferror(infp))
+       if (!issock && ferror(infp))
                goto bail;
 
        data = data_close(data);
index b2c7709812341ff7a89f571238bfb8ecbc33cbad..0d87b52428cc2724685216252c6ae7d4e13e80cc 100644 (file)
@@ -130,11 +130,11 @@ int               ftp_pasv(ftpbuf_t *ftp, int pasv);
 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
+/* stores the data from a file, socket, or process 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);
+                       int insocket, int issock, ftptype_t type);
 
 /* returns the size of the given file, or -1 on error */
 int            ftp_size(ftpbuf_t *ftp, const char *path);
index 130bee1776135c4a85337c866610d7f8a6f07632..f2ed4fe891e59240b2c14dd3106f820afc5544ba 100644 (file)
@@ -618,7 +618,8 @@ PHP_FUNCTION(ftp_fput)
        pval            *arg1, *arg2, *arg3, *arg4;
        ftpbuf_t        *ftp;
        ftptype_t       xtype;
-       FILE            *fp;
+       int             type;
+       void            *rsrc;
 
        /* arg1 - ftp
         * arg2 - remote file
@@ -633,10 +634,11 @@ PHP_FUNCTION(ftp_fput)
 
        FTPBUF(ftp, arg1);
        convert_to_string(arg2);
-       FILEP(fp, arg3);
+       rsrc = zend_fetch_resource(&arg3,-1,"File-Handle",&type,3,php_file_le_fopen(),php_file_le_popen(),php_file_le_socket());
+       ZEND_VERIFY_RESOURCE(rsrc);   
        XTYPE(xtype, arg4);
 
-       if (!ftp_put(ftp, Z_STRVAL_P(arg2), fp, xtype)) {
+       if (!ftp_put(ftp, Z_STRVAL_P(arg2), (FILE*)rsrc, *(int*) rsrc, (type==php_file_le_socket()), xtype)) {
                php_error(E_WARNING, "ftp_put: %s", ftp->inbuf);
                RETURN_FALSE;
        }
@@ -679,7 +681,7 @@ PHP_FUNCTION(ftp_put)
                php_error(E_WARNING, "error opening %s", Z_STRVAL_P(arg3));
                RETURN_FALSE;
        }
-       if (    !ftp_put(ftp, Z_STRVAL_P(arg2), infp, xtype) ||
+       if (    !ftp_put(ftp, Z_STRVAL_P(arg2), infp, 0, 0, xtype) ||
                ferror(infp))
        {
                fclose(infp);