ftp.class.php<?php
class ftp
{
protected $conn;
public $timeout=10;

/**
 * 连接FTP 
 * @param string $ip  -- FTP主机  
 * @param string $name -- 用户名
 * @param string $password -- 密码
 * @param int $port  -- 端口
 */
public function __construct($ip,$name,$password,$port=21)
{
$this->conn = @ftp_connect($ip,$port) or die("cannot connection ftp server");
if($this->timeout && function_exists('ftp_set_option')) {
ftp_set_option($this->conn, FTP_TIMEOUT_SEC, $this->timeout);
}
if(!@ftp_login($this->conn,$name,$password))
{
echo "FTP connection has failed! \n";
    echo "Attempted to connect to $ip for user $name \n"; 
    die; 
}
ftp_pasv($this->conn,false);//打开被动模式
}

//返回指定文件的最后修改时间
public function lastmodtime($value)
{
return ftp_mdtm ($this->conn,$value);
} //改变当前目录
public function changedir($targetdir)
{
return ftp_chdir($this->conn, $targetdir);
}

// 返回当前目路径
public function getdir()
{
return ftp_pwd($this->conn);
}

//返回给定目录的文件列表
public function get_file_list($directory){
$getback = ftp_nlist($this->conn, $directory);
return $getback;
}

//create dir
    public function mkdir($dir)
    {
     return ftp_mkdir($this->conn,$dir);
    }
    
    /**
     * 文件上传
     * @param unknown_type $localfile  -- 本地文件
     * @param unknown_type $remotefile -- 上传目标文件
     * @param unknown_type $dir        -- 路径
     */
    public function upload_file($localfile,$remotefile='',$dir)
    {
     if($remotefile =='')
     {
     $remotefile = end(explode("/",$localfile));
     }
     //创建目录,并切换到当前目录
     $respath = explode("/",$dir);
     if(is_array($respath))
     {
     foreach ($respath as $v)
     {
     if($this->changedir($v) === false)
     {
     if($this->mkdir($v) == false)
     {
     die("Directory create failure");
     }
     if(!function_exists('ftp_chmod') || !$this->chmod( 0777, $v)) {
//$this->site( "'CHMOD 0777 $v'");
}
     $this->changedir($v);
     }
     }
     }
     //return $this->put($remotefile,$localfile,FTP_BINARY);
     return $this->nb_put($remotefile,$localfile);    }
    
    public function nb_put($remotefile,$localfile)
    {
     if(!function_exists('ftp_chmod') || !$this->chmod( 0777, $remotefile)) {
//$this->site( "'CHMOD 0777 $remotefile'");
}
    $res = ftp_nb_put($this->conn,$remotefile,$localfile,FTP_ASCII,ftp_size($this->conn,$remotefile));//
     while ($res == FTP_MOREDATA)
     {
     $res = ftp_nb_continue($this->conn);
     }
      
     if ($res == FTP_FINISHED)
     {
     return true;
     }
     else 
     {
     return false;
     }
    }
public function chmod($mode, $filename) {
$mode = intval($mode);
$filename = $this->wipespecial($filename);
if(function_exists('ftp_chmod')) {
return @ftp_chmod($this->conn, $mode, $filename);
} else {
return $this->site('CHMOD '.$mode.' '.$filename);
}
}

public function put($remotefile, $localfile, $mode, $startpos = 0 ) 
{

$remote_file = $this->wipespecial($remotefile);
$local_file = $this->wipespecial($localfile);
$mode = intval($mode);
$startpos = intval($startpos);
return ftp_put($this->conn, $remote_file, $local_file, $mode, $startpos);
}
    //delete dir
public function rmdir($dir)
{
return ftp_rmdir($this->conn,$dir);
}

//delete file
public function delete($file)
{
return ftp_delete($this->conn,$file);
}



public function get_file_size($file)
{
return ftp_size($this->conn,$file);
}

public function get($remotefile,$localfile)
{
return ftp_get($this->conn,$localfile,$remotefile,FTP_ASCII);
}
public function wipespecial($str) {
return str_replace(array('..', "\n", "\r"), array('', '', ''), $str);
}

public function site($cmd) {
$cmd = $this->wipespecial($cmd);
return ftp_site($this->conn, $cmd);
}

public function __destruct()
{
ftp_close($this->conn);
}
}文件上传set_time_limit(0);
require_once 'kernel/ftp.class.php';
$Ip = "192.168.3.11";
$name = "admin";
$password = "admin";
$port = 21;
$basedir = "./chongwu/server_1";$todayfile = "20101130";
$localdir = "C:/databasebackup/".$todayfile.".rar";//
$ftp = new ftp($Ip,$name,$password,$port);
$res = $ftp -> upload_file($localdir,"","./chongwu/server_1");
问题:如果nb_put方法中$res = ftp_nb_put($this->conn,$remotefile,$localfile,FTP_ASCII,ftp_size($this->conn,$remotefile));//Warning: ftp_nb_put() [function.ftp-nb-put]: Transfer aborted. No space left on device in 
如果用二进制$res = ftp_nb_put($this->conn,$remotefile,$localfile,FTP_BINARY,ftp_size($this->conn,$remotefile));//Warning: ftp_nb_continue() [function.ftp-nb-continue]: Opening BINARY mode data connection for 20101130.rar从本地windows xp 上传到服务器 windows2003 可以正常上传
如果从服务器 windows2003  到备份服务器上linux 上 就会出现上面的错误,备份服务器上文件创建了,即有20101130.rar文件,但是没有任何内容,磁盘空间充足,用户权限没有问题