/**
  * @param Net_FTP $ftp
  * @param $remoteFileInformations
  * @param $directory
  * @return bool
  */
 private function _directoryInformations(Net_FTP $ftp, &$remoteFileInformations, $directory)
 {
     $content = $ftp->ls($directory);
     if (@PEAR::isError($content)) {
         if ($this->rawDataFallback) {
             $content = $ftp->ls($directory, NET_FTP_RAWLIST);
         }
         if (@PEAR::isError($content)) {
             return false;
         }
         $content = $this->parseRawFtpContent($content, $directory);
     }
     if (sizeof($content) == 0) {
         return false;
     } else {
         if (!empty($directory)) {
             $directory .= '/';
         }
         while (list(, $val) = each($content)) {
             if ($val['name'] != '.' && $val['name'] != '..') {
                 $remoteFileInformations[$directory . $val['name']] = $val;
             }
         }
         return true;
     }
 }
 public static function ftpLsRecursive(Net_FTP $ftp, $dir, $mode = null)
 {
     self::ftpInclude();
     if (null === $mode) {
         $mode = NET_FTP_DIRS_FILES;
     }
     // Ls
     $ret = $ftp->ls($dir, $mode);
     if (PEAR::isError($ret)) {
         throw new Engine_Package_Exception($ret->getMessage());
     }
     $results = $ret;
     $subdirs = array();
     foreach ($results as &$result) {
         $result['name'] = rtrim($dir, '/') . '/' . $result['name'];
         if ($result['is_dir'] == 'd') {
             $subdirs[] = $result['name'];
         }
     }
     foreach ($subdirs as $subdir) {
         try {
             $childResults = self::ftpLsRecursive($ftp, $subdir . '/', $mode);
         } catch (Exception $e) {
             continue;
             // @todo should we throw or ignore?
         }
         $results = array_merge($results, $childResults);
     }
     return $results;
 }
// 7. moves files on the FTP server
//
foreach ($files as $file) {
    $ret = $f->put($file, basename($file), $overwrite);
    if (PEAR::isError($ret)) {
        if ($ret->getCode() == NET_FTP_ERR_OVERWRITEREMOTEFILE_FORBIDDEN and !$overwrite) {
            printf('%s <br />', $ret->getMessage());
            continue;
            // it is just a warning when \$overwrite variable is set to false
        }
        die($ret->getMessage());
    }
    printf('<b>%s</b> transfer completed <br />', basename($file));
}
$f->detach($observer);
//
// 8. checks if files are really on the FTP server
//
$ret = $f->ls(null, NET_FTP_RAWLIST);
if (PEAR::isError($ret)) {
    $f->disconnect();
    die($ret->getMessage());
}
print '<pre>';
var_dump($ret);
print '</pre>';
//
// 9. says goodbye to the FTP server !
//
$f->disconnect();
echo 'Done!';
Exemple #4
0
head("\$ftp->setHostname({$host})");
Var_Dump::display($ftp->setHostname($host));
head("\$ftp->setPort({$port})");
Var_Dump::display($ftp->setPort($port));
head("\$ftp->connect({$host}, {$port})");
Var_Dump::display($ftp->connect());
head("\$ftp->setUsername({$user})");
Var_Dump::display($ftp->setUsername($user));
head("\$ftp->setPassword(xxx)");
Var_Dump::display($ftp->setPassword($pass));
head("\$ftp->login({$user}, xxx)");
Var_Dump::display($ftp->login($user, $pass));
head("\$ftp->pwd()");
Var_Dump::display($ftp->pwd());
head("\$ftp->ls(null, NET_FTP_DIRS_FILES)");
Var_Dump::display($ftp->ls(null, NET_FTP_DIRS_FILES));
head("\$ftp->mkdir({$baseDir})");
Var_Dump::display($ftp->mkdir($baseDir));
head("\$ftp->cd({$baseDir})");
Var_Dump::display($ftp->cd($baseDir));
head("\$ftp->ls(null, NET_FTP_RAWLIST)");
Var_Dump::display($ftp->ls(null, NET_FTP_RAWLIST));
head("\$ftp->put({$baseDir}{$singleTestFile}, {$singleTestFile})");
Var_Dump::display($ftp->put($baseDir . $singleTestFile, $singleTestFile));
head("\$ftp->ls(null, NET_FTP_FILES_ONLY)");
Var_Dump::display($ftp->ls(null, NET_FTP_FILES_ONLY));
head("\$ftp->put({$baseDir}{$singleTestFile}, {$singleTestFile}, true)");
Var_Dump::display($ftp->put($baseDir . $singleTestFile, $singleTestFile, true));
head("\$ftp->ls(null, NET_FTP_FILES_ONLY)");
Var_Dump::display($ftp->ls(null, NET_FTP_FILES_ONLY));
head("\$ftp->mdtm({$singleTestFile}, 'd.m.Y H:i:s')");
 private function _directoryInformations(Net_FTP $ftp, &$remoteFileInformations, $directory)
 {
     $content = $ftp->ls($directory);
     if (@PEAR::isError($content) || sizeof($content) == 0) {
         return false;
     } else {
         if (!empty($directory)) {
             $directory .= '/';
         }
         while (list(, $val) = each($content)) {
             if ($val['name'] != '.' && $val['name'] != '..') {
                 $remoteFileInformations[$directory . $val['name']] = $val;
             }
         }
         return true;
     }
 }