mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Add ftp_alloc() for servers which require client to predeclare filesize to be sent.
This commit is contained in:
parent
3efe102a48
commit
c553af47e0
4 changed files with 77 additions and 0 deletions
|
@ -605,6 +605,38 @@ ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filenam
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ ftp_alloc
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ftp_alloc(ftpbuf_t *ftp, const int size, char **response)
|
||||||
|
{
|
||||||
|
char buffer[64];
|
||||||
|
|
||||||
|
if (ftp == NULL || size <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buffer, 64, "%d", size);
|
||||||
|
|
||||||
|
if (!ftp_putcmd(ftp, "ALLO", buffer)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ftp_getresp(ftp)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response && ftp->inbuf) {
|
||||||
|
*response = estrdup(ftp->inbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ftp->resp < 200 || ftp->resp >= 300) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ ftp_nlist
|
/* {{{ ftp_nlist
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -141,6 +141,13 @@ int ftp_rmdir(ftpbuf_t *ftp, const char *dir);
|
||||||
/* Set permissions on a file */
|
/* Set permissions on a file */
|
||||||
int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len);
|
int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filename_len);
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
/* returns a NULL-terminated array of filenames in the given path
|
/* returns a NULL-terminated array of filenames in the given path
|
||||||
* or NULL on error. the return array must be freed (but don't
|
* or NULL on error. the return array must be freed (but don't
|
||||||
* free the array elements)
|
* free the array elements)
|
||||||
|
|
|
@ -50,6 +50,13 @@
|
||||||
static int le_ftpbuf;
|
static int le_ftpbuf;
|
||||||
#define le_ftpbuf_name "FTP Buffer"
|
#define le_ftpbuf_name "FTP Buffer"
|
||||||
|
|
||||||
|
static
|
||||||
|
ZEND_BEGIN_ARG_INFO(third_and_rest_force_ref, 1)
|
||||||
|
ZEND_ARG_PASS_INFO(0)
|
||||||
|
ZEND_ARG_PASS_INFO(0)
|
||||||
|
ZEND_ARG_PASS_INFO(1)
|
||||||
|
ZEND_END_ARG_INFO()
|
||||||
|
|
||||||
function_entry php_ftp_functions[] = {
|
function_entry php_ftp_functions[] = {
|
||||||
PHP_FE(ftp_connect, NULL)
|
PHP_FE(ftp_connect, NULL)
|
||||||
#ifdef HAVE_OPENSSL_EXT
|
#ifdef HAVE_OPENSSL_EXT
|
||||||
|
@ -64,6 +71,7 @@ function_entry php_ftp_functions[] = {
|
||||||
PHP_FE(ftp_mkdir, NULL)
|
PHP_FE(ftp_mkdir, NULL)
|
||||||
PHP_FE(ftp_rmdir, NULL)
|
PHP_FE(ftp_rmdir, NULL)
|
||||||
PHP_FE(ftp_chmod, NULL)
|
PHP_FE(ftp_chmod, NULL)
|
||||||
|
PHP_FE(ftp_alloc, third_and_rest_force_ref)
|
||||||
PHP_FE(ftp_nlist, NULL)
|
PHP_FE(ftp_nlist, NULL)
|
||||||
PHP_FE(ftp_rawlist, NULL)
|
PHP_FE(ftp_rawlist, NULL)
|
||||||
PHP_FE(ftp_systype, NULL)
|
PHP_FE(ftp_systype, NULL)
|
||||||
|
@ -430,6 +438,35 @@ PHP_FUNCTION(ftp_chmod)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ proto bool ftp_alloc(resource stream, int size[, &response])
|
||||||
|
Attempt to allocate space on the remote FTP server */
|
||||||
|
PHP_FUNCTION(ftp_alloc)
|
||||||
|
{
|
||||||
|
zval *z_ftp, *zresponse = NULL;
|
||||||
|
ftpbuf_t *ftp;
|
||||||
|
int size, ret;
|
||||||
|
char *response = NULL;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &z_ftp, &size, &zresponse) == FAILURE) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZEND_FETCH_RESOURCE(ftp, ftpbuf_t*, &z_ftp, -1, le_ftpbuf_name, le_ftpbuf);
|
||||||
|
|
||||||
|
ret = ftp_alloc(ftp, size, zresponse ? &response : NULL);
|
||||||
|
if (response) {
|
||||||
|
zval_dtor(zresponse);
|
||||||
|
ZVAL_STRING(zresponse, response, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TRUE;
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ proto array ftp_nlist(resource stream, string directory)
|
/* {{{ proto array ftp_nlist(resource stream, string directory)
|
||||||
Returns an array of filenames in the given directory */
|
Returns an array of filenames in the given directory */
|
||||||
PHP_FUNCTION(ftp_nlist)
|
PHP_FUNCTION(ftp_nlist)
|
||||||
|
|
|
@ -47,6 +47,7 @@ PHP_FUNCTION(ftp_raw);
|
||||||
PHP_FUNCTION(ftp_mkdir);
|
PHP_FUNCTION(ftp_mkdir);
|
||||||
PHP_FUNCTION(ftp_rmdir);
|
PHP_FUNCTION(ftp_rmdir);
|
||||||
PHP_FUNCTION(ftp_chmod);
|
PHP_FUNCTION(ftp_chmod);
|
||||||
|
PHP_FUNCTION(ftp_alloc);
|
||||||
PHP_FUNCTION(ftp_nlist);
|
PHP_FUNCTION(ftp_nlist);
|
||||||
PHP_FUNCTION(ftp_rawlist);
|
PHP_FUNCTION(ftp_rawlist);
|
||||||
PHP_FUNCTION(ftp_systype);
|
PHP_FUNCTION(ftp_systype);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue