/* {{{ 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;
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)
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);
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);
pval *arg1, *arg2, *arg3, *arg4;
ftpbuf_t *ftp;
ftptype_t xtype;
- FILE *fp;
+ int type;
+ void *rsrc;
/* arg1 - ftp
* arg2 - remote file
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;
}
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);