Exemple #1
0
 /**
  *
  * 发送一个配置命令远程FTP服务器对上传的文件分配空间。
  * 注:许多FTP服务器不支持这个命令。
  *
  * @param int $filesize 分配的字节数。
  * @param string $result 服务器的响应文本表示将通过引用返回的结果如果提供一个变量。
  * @return bool
  */
 public static function alloc($filesize, &$result = '')
 {
     return ftp_alloc(self::$resource, $filesize, $result);
 }
Exemple #2
0
<?php

require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) {
    die("Couldn't connect to the server");
}
ftp_login($ftp, 'user', 'pass');
var_dump(ftp_alloc($ftp, 1024));
Exemple #3
0
 /**
  * This function will upload a file to the ftp-server. You can either specify a
  * absolute path to the remote-file (beginning with "/") or a relative one,
  * which will be completed with the actual directory you selected on the server.
  * You can specify the path from which the file will be uploaded on the local
  * maschine, if the file should be overwritten if it exists (optionally, default
  * is no overwriting) and in which mode (FTP_ASCII or FTP_BINARY) the file
  * should be downloaded (if you do not specify this, the method tries to
  * determine it automatically from the mode-directory or uses the default-mode,
  * set by you).
  * If you give a relative path to the local-file, the script-path is used as
  * basepath.
  *
  * @param string $local_file  The local file to upload
  * @param string $remote_file The absolute or relative path to the file to
  *                            upload to
  * @param bool   $overwrite   (optional) Whether to overwrite existing file
  * @param int    $mode        (optional) Either FTP_ASCII or FTP_BINARY
  *
  * @access public
  * @return mixed True on success, otherwise PEAR::Error
  * @see NET_FTP_ERR_LOCALFILENOTEXIST,
  *      NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN,
  *      NET_FTP_ERR_UPLOADFILE_FAILED
  */
 function put($local_file, $remote_file, $overwrite = false, $mode = null)
 {
     if (!isset($mode)) {
         $mode = $this->checkFileExtension($local_file);
     }
     $remote_file = $this->_constructPath($remote_file);
     if (!@file_exists($local_file)) {
         return $this->raiseError("Local file '{$local_file}' does not exist.", NET_FTP_ERR_LOCALFILENOTEXIST);
     }
     if (@ftp_size($this->_handle, $remote_file) != -1 && !$overwrite) {
         return $this->raiseError("Remote file '" . $remote_file . "' exists and may not be overwriten.", NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN);
     }
     if (function_exists('ftp_alloc')) {
         ftp_alloc($this->_handle, filesize($local_file));
     }
     if (function_exists('ftp_nb_put')) {
         $res = @ftp_nb_put($this->_handle, $remote_file, $local_file, $mode);
         while ($res == FTP_MOREDATA) {
             $this->_announce('nb_put');
             $res = @ftp_nb_continue($this->_handle);
         }
     } else {
         $res = @ftp_put($this->_handle, $remote_file, $local_file, $mode);
     }
     if (!$res) {
         return $this->raiseError("File '{$local_file}' could not be uploaded to '" . $remote_file . "'.", NET_FTP_ERR_UPLOADFILE_FAILED);
     } else {
         return true;
     }
 }
Exemple #4
0
/**
* Little test suit
*/
$stream = ftp_connect($host);
if (is_resource($stream)) {
    dump('Logging in', $bool = ftp_login($stream, $user, $pass));
    if ($bool) {
        dump('PWD', ftp_pwd($stream));
        dump('Systype', ftp_systype($stream));
        dump('CHDIR "' . $dir . '"', ftp_chdir($stream, $dir));
        dump('PWD', ftp_pwd($stream));
        dump('CDUP', ftp_cdup($stream));
        dump('PASSIVE', ftp_pasv($stream, $pasv));
        dump('RAWLIST "."', ftp_rawlist($stream, '.'));
        dump('CHMOD', ftp_chmod($stream, 0777, 'sfv3.php'));
        dump('ALLOCATE', ftp_alloc($stream, filesize($Ubinary), $msg), $msg);
        dump('UPLOAD ASCII', ftp_put($stream, $Uasci, $Uasci, FTP_ASCII), $Uasci);
        dump('UPLOAD BINARY', ftp_put($stream, $Ubinary, $Ubinary, FTP_BINARY), $Ubinary);
        dump('RAWLIST "."', ftp_rawlist($stream, '.'));
        dump('DELETE ' . $Uasci, ftp_delete($stream, $Uasci));
        dump('DELETE ' . $Bbinary, ftp_delete($stream, $Ubinary));
        dump('RAWLIST "."', ftp_rawlist($stream, '.'));
    }
    dump('QUIT', ftp_quit($stream));
}
$end = microtime(true);
echo $end - $time;
?>

</pre>
 /**
  * Allocates space for a file to be uploaded
  * @link http://php.net/ftp_alloc
  *
  * @param  integer $filesize The number of bytes to allocate
  * @param  string  &$result  A textual representation of the servers response
  * @return boolean TRUE on success, FALSE on failure
  */
 public function alloc($filesize, &$result = null)
 {
     return ftp_alloc($this->connection->getStream(), $filesize, $result);
 }
Exemple #6
0
<?php

require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) {
    die("Couldn't connect to the server");
}
var_dump(ftp_login($ftp, 'user', 'pass'));
var_dump(ftp_systype($ftp));
/* some bogus usage */
var_dump(ftp_alloc($ftp, array()));
var_dump(ftp_cdup($ftp, 0));
var_dump(ftp_chdir($ftp, array()));
var_dump(ftp_chmod($ftp, 0666));
var_dump(ftp_get($ftp, 1234, 12));
var_dump(ftp_close());
var_dump(ftp_connect('sfjkfjaksfjkasjf'));
var_dump(ftp_delete($ftp, array()));
var_dump(ftp_exec($ftp, array()));
var_dump(ftp_systype($ftp, 0));
var_dump(ftp_pwd($ftp, array()));
var_dump(ftp_login($ftp));
var_dump(ftp_login($ftp, 'user', 'bogus'));
var_dump(ftp_quit($ftp));
Exemple #7
0
Fichier : FTP.php Projet : uda/jaws
 /**
  * This function will upload a file to the ftp-server. You can either specify a
  * absolute path to the remote-file (beginning with "/") or a relative one,
  * which will be completed with the actual directory you selected on the server.
  * You can specify the path from which the file will be uploaded on the local
  * maschine, if the file should be overwritten if it exists (optionally, default
  * is no overwriting) and in which mode (FTP_ASCII or FTP_BINARY) the file
  * should be downloaded (if you do not specify this, the method tries to
  * determine it automatically from the mode-directory or uses the default-mode,
  * set by you).
  * If you give a relative path to the local-file, the script-path is used as
  * basepath.
  *
  * @param string $local_file  The local file to upload
  * @param string $remote_file The absolute or relative path to the file to
  *                            upload to
  * @param bool   $overwrite   (optional) Whether to overwrite existing file
  * @param int    $mode        (optional) Either FTP_ASCII or FTP_BINARY
  * @param int    $options     (optional) Flags describing the behaviour of this
  *                            function. Currently NET_FTP_BLOCKING and 
  *                            NET_FTP_NONBLOCKING are supported, of which
  *                            NET_FTP_NONBLOCKING is the default.
  *
  * @access public
  * @return mixed True on success, otherwise PEAR::Error
  * @see NET_FTP_ERR_LOCALFILENOTEXIST,
  *      NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN,
  *      NET_FTP_ERR_UPLOADFILE_FAILED, NET_FTP_NONBLOCKING, NET_FTP_BLOCKING
  */
 function put($local_file, $remote_file, $overwrite = false, $mode = null, $options = 0)
 {
     if ($options & (NET_FTP_BLOCKING | NET_FTP_NONBLOCKING) === (NET_FTP_BLOCKING | NET_FTP_NONBLOCKING)) {
         return $this->raiseError('Bad options given: NET_FTP_NONBLOCKING and ' . 'NET_FTP_BLOCKING can\'t both be set', NET_FTP_ERR_BADOPTIONS);
     }
     $usenb = !($options & NET_FTP_BLOCKING == NET_FTP_BLOCKING);
     if (!isset($mode)) {
         $mode = $this->checkFileExtension($local_file);
     }
     $remote_file = $this->_constructPath($remote_file);
     if (!@file_exists($local_file)) {
         return $this->raiseError("Local file '{$local_file}' does not exist.", NET_FTP_ERR_LOCALFILENOTEXIST);
     }
     if (@ftp_size($this->_handle, $remote_file) != -1 && !$overwrite) {
         return $this->raiseError("Remote file '" . $remote_file . "' exists and may not be overwriten.", NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN);
     }
     if (function_exists('ftp_alloc')) {
         ftp_alloc($this->_handle, filesize($local_file));
     }
     if ($usenb && function_exists('ftp_nb_put')) {
         $res = @ftp_nb_put($this->_handle, $remote_file, $local_file, $mode);
         while ($res == FTP_MOREDATA) {
             $this->_announce('nb_put');
             $res = @ftp_nb_continue($this->_handle);
         }
     } else {
         $res = @ftp_put($this->_handle, $remote_file, $local_file, $mode);
     }
     if (!$res) {
         return $this->raiseError("File '{$local_file}' could not be uploaded to '" . $remote_file . "'.", NET_FTP_ERR_UPLOADFILE_FAILED);
     } else {
         return true;
     }
 }
Exemple #8
0
<?php

require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) {
    die("Couldn't connect to the server");
}
ftp_login($ftp, 'user', 'pass');
var_dump(ftp_alloc($ftp, 1024, $result));
var_dump($result);
Exemple #9
0
 public function put($local_file, $remote_file, $overwrite = false, $mode = null, $options = 0)
 {
     if ($options & (FILE_FTP_BLOCKING | FILE_FTP_NONBLOCKING) === (FILE_FTP_BLOCKING | FILE_FTP_NONBLOCKING)) {
         throw new FTPException("Bad options given: FILE_FTP_NONBLOCKING and '. 'FILE_FTP_BLOCKING can't both be set");
     }
     $usenb = !($options & FILE_FTP_BLOCKING == FILE_FTP_BLOCKING);
     if (!isset($mode)) {
         $mode = $this->checkFileExtension($local_file);
     }
     $remote_file = $this->constructPath($remote_file);
     if (!file_exists($local_file)) {
         throw new FTPException("Local file '{$local_file}' does not exist.");
     }
     if (ftp_size($this->handle, $remote_file) != -1 && !$overwrite) {
         throw new FTPException("Remote file '" . $remote_file . "' exists and may not be overwriten.");
     }
     if (function_exists('ftp_alloc')) {
         ftp_alloc($this->handle, filesize($local_file));
     }
     if ($usenb && function_exists('ftp_nb_put')) {
         $res = ftp_nb_put($this->handle, $remote_file, $local_file, $mode);
         while ($res == FTP_MOREDATA) {
             $res = ftp_nb_continue($this->handle);
         }
     } else {
         $res = ftp_put($this->handle, $remote_file, $local_file, $mode);
     }
     if (!$res) {
         throw new FTPException("File '{$local_file}' could not be uploaded to '" . $remote_file . "'.");
     }
     return true;
 }
Exemple #10
0
 /**
  * Allocates space for a file to be uploaded
  * 
  * @param int $filesize
  * 
  * @return FTPClient
  */
 public function allocate($filesize)
 {
     $result = @ftp_alloc($this->connection, $filesize);
     if ($result === false) {
         throw new Exception('Unable to allocate');
     }
     return $this;
 }
 function alloc($size, &$msg)
 {
     return ftp_alloc($this->_connection, $size, $msg);
 }
Exemple #12
0
<?php

$bogus = 1;
require 'server.inc';
$ftp = ftp_connect('127.0.0.1', $port);
if (!$ftp) {
    die("Couldn't connect to the server");
}
var_dump(ftp_login($ftp, 'anonymous', '*****@*****.**'));
var_dump(ftp_alloc($ftp, 400));
var_dump(ftp_cdup($ftp));
var_dump(ftp_chdir($ftp, '~'));
var_dump(ftp_chmod($ftp, 0666, 'x'));
var_dump(ftp_delete($ftp, 'x'));
var_dump(ftp_exec($ftp, 'x'));
var_dump(ftp_fget($ftp, STDOUT, 'x', 0));
var_dump(ftp_fput($ftp, 'x', fopen(__FILE__, 'r'), 0));
var_dump(ftp_get($ftp, 'x', 'y', 0));
var_dump(ftp_mdtm($ftp, 'x'));
var_dump(ftp_mkdir($ftp, 'x'));
var_dump(ftp_nb_continue($ftp));
var_dump(ftp_nb_fget($ftp, STDOUT, 'x', 0));
var_dump(ftp_nb_fput($ftp, 'x', fopen(__FILE__, 'r'), 0));
var_dump(ftp_systype($ftp));
var_dump(ftp_pwd($ftp));
var_dump(ftp_size($ftp, ''));
var_dump(ftp_rmdir($ftp, ''));