コード例 #1
2
 /**
  * @param string $file
  */
 private function clean($file)
 {
     if (ftp_size($this->connection, $file) == -1) {
         $result = ftp_nlist($this->connection, $file);
         foreach ($result as $childFile) {
             $this->clean($childFile);
         }
         ftp_rmdir($this->connection, $file);
     } else {
         ftp_delete($this->connection, $file);
     }
 }
コード例 #2
0
ファイル: Info.php プロジェクト: znframework/znframework
 public function fileSize(string $path, string $type = 'b', int $decimal = 2) : float
 {
     $size = 0;
     $extension = extension($path);
     if (!empty($extension)) {
         $size = ftp_size($this->connect, $path);
     } else {
         if ($this->files($path)) {
             foreach ($this->files($path) as $val) {
                 $size += ftp_size($this->connect, $path . "/" . $val);
             }
             $size += ftp_size($this->connect, $path);
         } else {
             $size += ftp_size($this->connect, $path);
         }
     }
     if ($type === "b") {
         return $size;
     }
     if ($type === "kb") {
         return round($size / 1024, $decimal);
     }
     if ($type === "mb") {
         return round($size / (1024 * 1024), $decimal);
     }
     if ($type === "gb") {
         return round($size / (1024 * 1024 * 1024), $decimal);
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function size(BucketInterface $bucket, $name)
 {
     if (($size = ftp_size($this->connection, $this->getPath($bucket, $name))) != -1) {
         return $size;
     }
     return false;
 }
コード例 #4
0
ファイル: class_ftp.php プロジェクト: Eun/developer
 public function downloadToTemp($pathAndFile, $startAt = 0, $files = false)
 {
     $pathAndFile = $this->removeSlashes($pathAndFile);
     if (is_array($files)) {
         $this->tempHandle = array();
         foreach ($files as $file) {
             $arrayCombined = $this->removeSlashes($pathAndFile . '/' . $file);
             $fileSize = @ftp_size($this->ftpConnection, $arrayCombined);
             if ($fileSize != -1) {
                 $this->tempHandle[$file] = tmpfile();
                 @ftp_fget($this->ftpConnection, $this->tempHandle[$file], $arrayCombined, FTP_BINARY, 0);
                 fseek($this->tempHandle[$file], 0);
             }
         }
     } else {
         $fileSize = @ftp_size($this->ftpConnection, $pathAndFile);
         if ($fileSize != -1) {
             $startAtSize = ($startAt != 0 and $fileSize > $startAt) ? $fileSize - $startAt : 0;
             $this->tempHandle = tmpfile();
             $download = @ftp_fget($this->ftpConnection, $this->tempHandle, $pathAndFile, FTP_BINARY, $startAtSize);
             fseek($this->tempHandle, 0);
             if ($download) {
                 return true;
             }
         }
     }
     return false;
 }
コード例 #5
0
ファイル: list.php プロジェクト: hoksi/mangolight-editor
function build_content($ftp, $dir)
{
    $content_array = array();
    $dirs_array = array();
    $files_array = array();
    $files = ftp_nlist($ftp, $dir);
    foreach ($files as $filename) {
        $filename = explode('/', $filename);
        $filename = $filename[count($filename) - 1];
        if ($filename == '.' || $filename == '..') {
            continue;
        }
        $fullname = $filename;
        if ($dir != '') {
            $fullname = $dir . '/' . $fullname;
        }
        $filename = utf8_encode($filename);
        if (ftp_size($ftp, $fullname) == -1) {
            $fullname = utf8_encode($fullname);
            $dirs_array[] = array('name' => $filename, 'file' => $fullname, 'is_folder' => 'true');
        } else {
            $fullname = utf8_encode($fullname);
            $files_array[] = array('name' => $filename, 'file' => $fullname, 'icon' => get_icon($filename));
        }
    }
    usort($dirs_array, 'cmp');
    usort($files_array, 'cmp');
    $content_array = array_merge($dirs_array, $files_array);
    return $content_array;
}
コード例 #6
0
ファイル: ftp.fun.php プロジェクト: polarlight1989/08cms
 function msize($remote_file)
 {
     if (!$this->conn_id) {
         return false;
     }
     return @ftp_size($this->conn_id, $remote_file);
 }
コード例 #7
0
ファイル: Ftp.php プロジェクト: Rudi9719/lucid
 function _getFileInfo($path)
 {
     //$curdir = ftp_pwd($this->_link);
     //$isDir = @ftp_chdir($this->_link, $path);
     //ftp_chdir($this->_link, $curdir);
     $size = ftp_size($this->_link, $path);
     return array(name => basename($path), modified => ftp_mdtm($this->_link, $path), size => $size, type => $size == -1 ? "text/directory" : "text/plain");
 }
コード例 #8
0
 function is_exists($file)
 {
     $res = ftp_size($this->con, $file);
     if ($res != -1) {
         return true;
     } else {
         return false;
     }
 }
コード例 #9
0
ファイル: File.php プロジェクト: robik/cFTP
 /**
  * Gets file size
  * 
  * @throws cFTP_Exception
  *
  * @return int File size 
  */
 public function getSize()
 {
     $res = @ftp_size($this->handle, $this->name);
     
     if( $res == -1 )
         throw new cFTP_Exception( "Could not get file size", 32 );
     
     return $res;
 }
コード例 #10
0
ファイル: ftp.php プロジェクト: natgeo/kids-myshot
 public function delete($file)
 {
     if (ftp_size($this->connection, $file) != -1) {
         $delete = ftp_delete($this->connection, $file);
         if ($delete) {
         } else {
         }
     }
     return $this;
 }
コード例 #11
0
 /**
  * Remote file size function for streams that don't support it
  *
  * @param   string  $url  TODO Add text
  *
  * @return  mixed
  *
  * @see     http://www.php.net/manual/en/function.filesize.php#71098
  * @since   11.1
  */
 function remotefsize($url)
 {
     $sch = parse_url($url, PHP_URL_SCHEME);
     if ($sch != 'http' && $sch != 'https' && $sch != 'ftp' && $sch != 'ftps') {
         return false;
     }
     if ($sch == 'http' || $sch == 'https') {
         $headers = get_headers($url, 1);
         if (!array_key_exists('Content-Length', $headers)) {
             return false;
         }
         return $headers['Content-Length'];
     }
     if ($sch == 'ftp' || $sch == 'ftps') {
         $server = parse_url($url, PHP_URL_HOST);
         $port = parse_url($url, PHP_URL_PORT);
         $path = parse_url($url, PHP_URL_PATH);
         $user = parse_url($url, PHP_URL_USER);
         $pass = parse_url($url, PHP_URL_PASS);
         if (!$server || !$path) {
             return false;
         }
         if (!$port) {
             $port = 21;
         }
         if (!$user) {
             $user = '******';
         }
         if (!$pass) {
             $pass = '';
         }
         switch ($sch) {
             case 'ftp':
                 $ftpid = ftp_connect($server, $port);
                 break;
             case 'ftps':
                 $ftpid = ftp_ssl_connect($server, $port);
                 break;
         }
         if (!$ftpid) {
             return false;
         }
         $login = ftp_login($ftpid, $user, $pass);
         if (!$login) {
             return false;
         }
         $ftpsize = ftp_size($ftpid, $path);
         ftp_close($ftpid);
         if ($ftpsize == -1) {
             return false;
         }
         return $ftpsize;
     }
 }
コード例 #12
0
ファイル: ftp.class.php プロジェクト: brandmobility/kikbak
 public function put($local_file_path, $remote_file_path, $mode = FTP_BINARY, $resume = false, $updraftplus = false)
 {
     $file_size = filesize($local_file_path);
     $existing_size = 0;
     if ($resume) {
         $existing_size = ftp_size($this->conn_id, $remote_file_path);
         if ($existing_size <= 0) {
             $resume = false;
             $existing_size = 0;
         } else {
             if (is_a($updraftplus, 'UpdraftPlus')) {
                 $updraftplus->log("File already exists at remote site: size {$existing_size}. Will attempt resumption.");
             }
             if ($existing_size >= $file_size) {
                 if (is_a($updraftplus, 'UpdraftPlus')) {
                     $updraftplus->log("File is apparently already completely uploaded");
                 }
                 return true;
             }
         }
     }
     // From here on, $file_size is only used for logging calculations. We want to avoid divsion by zero.
     $file_size = max($file_size, 1);
     if (!($fh = fopen($local_file_path, 'rb'))) {
         return false;
     }
     if ($existing_size) {
         fseek($fh, $existing_size);
     }
     $ret = ftp_nb_fput($this->conn_id, $remote_file_path, $fh, FTP_BINARY, $existing_size);
     // $existing_size can now be re-purposed
     while ($ret == FTP_MOREDATA) {
         if (is_a($updraftplus, 'UpdraftPlus')) {
             $new_size = ftell($fh);
             if ($new_size - $existing_size > 524288) {
                 $existing_size = $new_size;
                 $percent = round(100 * $new_size / $file_size, 1);
                 $updraftplus->record_uploaded_chunk($percent, '', $local_file_path);
             }
         }
         // Continue upload
         $ret = ftp_nb_continue($this->conn_id);
     }
     fclose($fh);
     if ($ret != FTP_FINISHED) {
         if (is_a($updraftplus, 'UpdraftPlus')) {
             $updraftplus->log("FTP upload: error ({$ret})");
         }
         return false;
     }
     return true;
 }
コード例 #13
0
ファイル: ftp.php プロジェクト: braxtondiggs/Clefable
 function browse_file($action = null, $id = null)
 {
     if ($this->input->is_ajax_request()) {
         $ftp_server = trim($this->input->post('server'));
         $ftp_user = trim($this->input->post('username'));
         $ftp_password = trim($this->input->post('password'));
         $port = trim($this->input->post('port'));
         $dir = trim($this->input->post('dir'));
         $sftp = $this->input->post('SFTP');
         if ($dir === "." || $dir === "./" || $dir === "//" || $dir === "../" || $dir === "/./" || $dir === "") {
             $dir = "/";
         }
         if ($action === "index") {
             $allowed_extentions = array("htm", "html", "php");
         } else {
             if ($action === "img") {
                 $allowed_extentions = array("jpg", "jpeg", "gif", "png", "bmp", "psd", "pxd");
             } else {
                 if ($action === "docs") {
                     $allowed_extentions = array("txt", "pdf", "doc", "docx", "log", "rtf", "ppt", "pptx", "swf");
                 }
             }
         }
         $this->_open_connection($ftp_server, $ftp_user, $ftp_password, $port, $sftp);
         $ftp_nlist = $this->ftp->list_files($dir);
         sort($ftp_nlist);
         $output = '<ul class="jqueryFileTree" style="display: none;">';
         foreach ($ftp_nlist as $folder) {
             //1. Size is '-1' => directory
             if (@ftp_size($this->ftp->conn_id, $dir . $folder) == '-1' && $folder !== "." && $folder !== "..") {
                 //output as [ directory ]
                 $output .= '<li class="directory collapsed"><a href="' . $folder . '" rel="' . $dir . htmlentities($folder) . '/' . '">' . htmlentities($folder) . '</a></li>';
             }
         }
         foreach ($ftp_nlist as $file) {
             //2. Size is not '-1' => file
             if (!(@ftp_size($this->ftp->conn_id, $dir . $file) == '-1')) {
                 //output as file
                 $ext = preg_replace('/^.*\\./', '', $file);
                 if (in_array($ext, $allowed_extentions)) {
                     $output .= '<li class="file ext_' . $ext . '"><a href="' . htmlentities($file) . '" rel="' . $dir . htmlentities($file) . '">' . htmlentities($file) . '</a></li>';
                 }
             }
         }
         echo $output . '</ul>';
         $this->ftp->close();
     } else {
         show_404();
     }
 }
コード例 #14
0
ファイル: ftp.php プロジェクト: nikosv/openeclass
 protected function getFileList($connection, $path) {
     @ftp_chdir($connection, $path);
     $list = ftp_nlist($connection, ".");
     $files = array();
     if ($list) {
         foreach ($list as $filename) {
             $fullpath = strlen($path) < 1 ? $filename : $path . "/" . $filename;
             $size = ftp_size($connection, $filename);
             $files[] = new CloudFile($filename, $fullpath, $size < 0, $size, $this->getName());
         }
     }
     ftp_close($connection);
     return $files;
 }
コード例 #15
0
ファイル: EdiInterface.php プロジェクト: uzerpllp/uzerp
 function getFileList(&$errors = array())
 {
     $filelist = array();
     if ($this->direction == 'IN') {
         switch (strtoupper($this->transfer_type)) {
             case 'FTP':
                 $conn = $this->ftpConnection($errors);
                 if (!$conn || count($errors) > 0) {
                     $errors[] = 'Error connecting to remote site to get file list';
                     return false;
                 }
                 $external_list = ftp_nlist($conn, ".");
                 foreach ($external_list as $key => $file) {
                     if (ftp_size($conn, $file) == -1 || $file == '.' || $file == '..') {
                         unset($external_list[$key]);
                     }
                 }
                 foreach ($external_list as $id) {
                     $filelist[$id] = $this->file_prefix . $id . (!empty($this->file_extension) ? '.' . strtolower($this->file_extension) : '');
                 }
                 asort($filelist);
                 ftp_close($conn);
                 break;
             case 'LOCAL':
                 $filepath = $this->get_file_path();
                 $handle = opendir($filepath);
                 while (false !== ($file = readdir($handle))) {
                     if ($file != "." && $file != ".." && !is_dir($filepath . DIRECTORY_SEPARATOR . $file) && substr($file, 0, strlen($this->file_prefix)) == $this->file_prefix && substr($file, -strlen($this->file_extension)) == $this->file_extension) {
                         $filelist[$file] = $file;
                     }
                 }
                 closedir($handle);
                 break;
             default:
                 $errors[] = $this->transfer_type . ' transfer type not supported';
         }
         return $filelist;
     }
     // Direction is not 'IN'
     $extractlist = array();
     if (!empty($this->process_model) && !empty($this->process_function) && method_exists($this->process_model, $this->process_function)) {
         $model = new $this->process_model();
         $extractlist = call_user_func(array($model, $this->process_function), $this->id);
         foreach ($extractlist as $key => $value) {
             $extractlist[$key] = $this->file_prefix . $value . (!empty($this->file_extension) ? '.' . strtolower($this->file_extension) : '');
         }
     }
     return $extractlist;
 }
コード例 #16
0
ファイル: remote.php プロジェクト: lz1988/stourwebcms
 public function image_dir_scan($dir, $basedir)
 {
     $data = array();
     $dir = $basedir . $dir;
     $files = ftp_rawlist($this->link, $dir);
     foreach ($files as $v) {
         $file = ltrim(strrchr($v, ' '), ' ');
         $path = "{$dir}/{$file}";
         if (preg_match('/^-/', $v)) {
             if (preg_match('/^[a-zA-z0-9]+\\.(gif|png|jpg|jpeg)$/', $file)) {
                 //遍历目录设置
                 array_push($data, array(str_replace($basedir, '', $path), ftp_size($this->link, $path)));
             }
         }
     }
     return $data;
 }
コード例 #17
0
ファイル: ftpMgr.class.php プロジェクト: richhl/kalturaCE
 protected function doFileExists($remote_file)
 {
     // check if exists as file
     if (ftp_size($this->getConnection(), $remote_file) != -1) {
         return true;
         // file exists
     }
     // check if exists as dir
     $pwd = ftp_pwd($this->getConnection());
     if (ftp_chdir($this->getConnection(), $remote_file)) {
         ftp_chdir($this->getConnection(), $pwd);
         return true;
         // dir exists
     }
     // does not exist
     return false;
 }
コード例 #18
0
ファイル: ftp.php プロジェクト: magix-cms/magixcms-3
 /**
  * @access public
  * Affiche les données du fichier en cours de téléchargement (comparaison local et distante)
  * @param $server_file
  * @return string
  */
 public function remoteFileCmp($server_file)
 {
     // Récupération de la taille du fichier $file
     $res = ftp_size($this->ftpConnect(), $server_file);
     if ($res != -1) {
         //echo 'La taille du fichier '.self::SERVERFILE.' est de '.$res.' octets sur le serveur<br />';
         $getFileSize = $res;
     } else {
         //echo "Impossible de récupérer la taille du fichier";
         $getFileSize = '';
     }
     /*On ferme la connexion FTP*/
     ftp_close($this->ftpConnect());
     $comp = $getFileSize;
     return $comp;
     //print 'Taille du fichier local : '.filesize(self::LOCALFILE).' octets';
 }
コード例 #19
0
ファイル: Ftp.php プロジェクト: hukumonline/admin
 function rmAll($dst_dir, $debug = 0)
 {
     if (!$dst_dir) {
         return false;
         exit;
     }
     $dst_dir = preg_replace("/\\/\$/", "", $dst_dir);
     // remove trailing slash
     $ar_files = ftp_nlist($this->conn_id, $dst_dir);
     if (is_array($ar_files)) {
         // makes sure there are files
         if (count($ar_files) == 1) {
             // if its only a file
             return ftp_delete($this->conn_id, $ar_files[0]);
         } else {
             foreach ($ar_files as $st_file) {
                 // for each file
                 if ($st_file == "." || $st_file == "..") {
                     continue 1;
                 }
                 $fl_file = "{$dst_dir}/{$st_file}";
                 $ftp_size = ftp_size($this->conn_id, $fl_file);
                 if ($ftp_size == -1) {
                     // check if it is a directory
                     $this->rmAll($fl_file);
                     // if so, use recursion
                 } else {
                     if ($debug) {
                         echo "File: {$fl_file} | {$ftp_size}\n";
                     } else {
                         ftp_delete($this->conn_id, $fl_file);
                     }
                     // if not, delete the file
                 }
             }
         }
     }
     if ($debug) {
         echo "Dir: {$dst_dir} \n";
     } elseif (count($ar_files) != 1) {
         echo @ftp_rmdir($this->conn_id, $dst_dir) ? "{$dst_dir} deleted!\n" : "Can't remove {$dst_dir}: No such file or directory";
     }
     // delete empty directories
 }
コード例 #20
0
ファイル: arrayToCsv.php プロジェクト: nignjatov/TaxiDev
 public function isFileExist($fileName)
 {
     try {
         $conn_id = $this->CI->util->connectFTPServer('azure');
         if ($conn_id) {
             $file = $this->dataFolder . $fileName . '.csv';
             $res = ftp_size($conn_id, $file);
             $this->CI->util->closeFTPConnection($conn_id);
             return $res != -1;
         } else {
             return false;
         }
     } catch (Exception $e) {
         echo "Error: <br>";
         $this->CI->util->echoObject($e);
         return false;
     } catch (ErrorException $e) {
         echo "Error: <br>";
         $this->CI->util->echoObject($e);
         return false;
     }
 }
コード例 #21
0
ファイル: BackendInstall.php プロジェクト: eknoes/core
 /**
  * Store the FTP login credentials
  */
 protected function storeFtpCredentials()
 {
     if (\Config::get('installPassword') != '') {
         return;
     }
     \Config::set('useFTP', true);
     \Config::set('ftpHost', \Input::post('host'));
     \Config::set('ftpPath', \Input::post('path'));
     \Config::set('ftpUser', \Input::post('username', true));
     if (\Input::postUnsafeRaw('password') != '*****') {
         \Config::set('ftpPass', \Input::postUnsafeRaw('password'));
     }
     \Config::set('ftpSSL', \Input::post('ssl'));
     \Config::set('ftpPort', (int) \Input::post('port'));
     // Add a trailing slash
     if (\Config::get('ftpPath') != '' && substr(\Config::get('ftpPath'), -1) != '/') {
         \Config::set('ftpPath', \Config::get('ftpPath') . '/');
     }
     // Re-insert the data into the form
     $this->Template->ftpHost = \Config::get('ftpHost');
     $this->Template->ftpPath = \Config::get('ftpPath');
     $this->Template->ftpUser = \Config::get('ftpUser');
     $this->Template->ftpPass = \Config::get('ftpPass') != '' ? '*****' : '';
     $this->Template->ftpSSL = \Config::get('ftpSSL');
     $this->Template->ftpPort = \Config::get('ftpPort');
     $ftp_connect = \Config::get('ftpSSL') && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
     // Try to connect and locate the Contao directory
     if (($resFtp = $ftp_connect(\Config::get('ftpHost'), \Config::get('ftpPort'), 5)) == false) {
         $this->Template->ftpHostError = true;
         $this->outputAndExit();
     } elseif (!ftp_login($resFtp, \Config::get('ftpUser'), \Config::get('ftpPass'))) {
         $this->Template->ftpUserError = true;
         $this->outputAndExit();
     } elseif (ftp_size($resFtp, \Config::get('ftpPath') . 'assets/contao/css/debug.css') == -1) {
         $this->Template->ftpPathError = true;
         $this->outputAndExit();
     } else {
         $this->import('Files');
         // The system/tmp folder must be writable for fopen()
         if (!is_writable(TL_ROOT . '/system/tmp')) {
             $this->Files->chmod('system/tmp', 0777);
         }
         // The assets/images folder must be writable for image*()
         if (!is_writable(TL_ROOT . '/assets/images')) {
             $this->Files->chmod('assets/images', 0777);
         }
         $folders = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
         foreach ($folders as $folder) {
             if (!is_writable(TL_ROOT . '/assets/images/' . $folder)) {
                 $this->Files->chmod('assets/images/' . $folder, 0777);
             }
         }
         // The system/logs folder must be writable for error_log()
         if (!is_writable(TL_ROOT . '/system/logs')) {
             $this->Files->chmod('system/logs', 0777);
         }
         // Create the local configuration files
         $this->createLocalConfigurationFiles();
         // Save the FTP credentials
         \Config::persist('useFTP', true);
         \Config::persist('ftpHost', \Config::get('ftpHost'));
         \Config::persist('ftpPath', \Config::get('ftpPath'));
         \Config::persist('ftpUser', \Config::get('ftpUser'));
         if (\Input::postUnsafeRaw('password') != '*****') {
             \Config::persist('ftpPass', \Config::get('ftpPass'));
         }
         \Config::persist('ftpSSL', \Config::get('ftpSSL'));
         \Config::persist('ftpPort', \Config::get('ftpPort'));
         $this->reload();
     }
 }
コード例 #22
0
ファイル: discuz_ftp.php プロジェクト: softhui/discuz
 function ftp_size($remote_file)
 {
     $remote_file = discuz_ftp::clear($remote_file);
     return @ftp_size($this->connectid, $remote_file);
 }
コード例 #23
0
ファイル: ftpclient.php プロジェクト: luisbrito/Phraseanet
 public function filesize($remotefile)
 {
     $remotefile = $this->get_absolute_path($remotefile);
     if ($this->debug) {
         echo "Recuperation de la taille du fichier {$remotefile}\n<br>";
     }
     if (($size = @ftp_size($this->connexion, $remotefile)) === false) {
         throw new Exception('Impossible de recuperer la taille du fichier');
     }
     return $size;
 }
コード例 #24
0
 /**
  * @param string $file
  * @return int
  */
 public function size($file)
 {
     return ftp_size($this->link, $file);
 }
コード例 #25
0
function escribe_archivo_via_ftp($cadena, $nombre_archivo_remoto = "", $mensajes = 0)
{
    $fp = fopen("temp.txt", "w");
    if (fwrite($fp, utf8_encode($cadena))) {
        $ftp_sitio = "www.ingenierosdigitales.com";
        $ftp_usuario = "*****@*****.**";
        $ftp_pass = "******";
        //  $ftp_sitio="demo-partners.xsa.com.mx";
        //  $ftp_usuario="testftpfacciisa";
        //  $ftp_pass="******";
        $conn = ftp_connect($ftp_sitio) or die("Could not connect to " . $ftp_sitio);
        ftp_login($conn, $ftp_usuario, $ftp_pass);
        if (ftp_size($conn, $nombre_archivo_remoto) != -1) {
            if ($mensajes) {
                echo "Ya existe este envio, no se realizo nuevamente..";
            }
        } else {
            if (ftp_put($conn, $nombre_archivo_remoto, "temp.txt", FTP_ASCII)) {
                if ($mensajes) {
                    echo "Envio exitoso.... ok";
                } else {
                    if ($mensajes) {
                        echo "Hubo un problema durante la transferencia ...";
                    }
                }
            }
        }
        ftp_close($conn);
    }
    fclose($fp);
}
コード例 #26
0
ファイル: function_ftp.php プロジェクト: NaturalWill/UCQA
function sftp_size($ftp_stream, $remote_file)
{
    $remote_file = wipespecial($remote_file);
    return @ftp_size($ftp_stream, $remote_file);
}
コード例 #27
0
$login_result = ftp_login($conn_id, $user, $password);
// Verbindung �berpr�fen
if (!$conn_id || !$login_result) {
    echo "Ftp-Verbindung nicht hergestellt!";
    echo "Verbindung mit {$host} als Benutzer {$user} nicht m�glich";
    die;
} else {
    echo "Verbunden mit {$host} als Benutzer {$user}";
}
print "<br>";
$path = "/";
$dir = "";
///// List
$files = ftp_nlist($conn_id, "{$path}");
foreach ($files as $file) {
    $isfile = ftp_size($conn_id, $file);
    if ($isfile == "-1") {
        // Ist ein Verzeichnis
        print $file . "/ [DIR]<br>";
    } else {
        $filelist[count($filelist) + 1] = $file;
        // Ist eine Verzeichnis
        print $file . "<br>";
    }
}
///// Upload
// ftp_put($conn_id, $remote_file_path, $local_file_path, FTP_BINARY);
///// Download
// ftp_get($conn_id, $local_file_path, $remote_file_path, FTP_BINARY);
///// L�schen einer Datei
// ftp_delete ($conn_id, $remote_file_path);
コード例 #28
0
ファイル: Ftp.php プロジェクト: trendyta/bestilblomster
 /**
  * Uploads files to FTP
  *
  * @param array $files
  * @param array $results
  * @param boolean $force_rewrite
  * @return boolean
  */
 function upload($files, &$results, $force_rewrite = false)
 {
     $error = null;
     if (!$this->_connect($error)) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, $error);
         return false;
     }
     $this->_set_error_handler();
     $home = @ftp_pwd($this->_ftp);
     if ($home === false) {
         $results = $this->_get_results($files, W3TC_CDN_RESULT_HALT, sprintf('Unable to get current directory (%s).', $this->_get_last_error()));
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     foreach ($files as $file) {
         $local_path = $file['local_path'];
         $remote_path = $file['remote_path'];
         if (!file_exists($local_path)) {
             $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, 'Source file not found.');
             continue;
         }
         @ftp_chdir($this->_ftp, $home);
         $remote_dir = dirname($remote_path);
         $remote_dirs = preg_split('~\\/+~', $remote_dir);
         foreach ($remote_dirs as $dir) {
             if (!@ftp_chdir($this->_ftp, $dir)) {
                 if (!@ftp_mkdir($this->_ftp, $dir)) {
                     $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to create directory (%s).', $this->_get_last_error()));
                     continue 2;
                 }
                 if (!@ftp_chdir($this->_ftp, $dir)) {
                     $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to change directory (%s).', $this->_get_last_error()));
                     continue 2;
                 }
             }
         }
         // basename cannot be used, kills chinese chars and similar characters
         $remote_file = substr($remote_path, strrpos($remote_path, '/') + 1);
         $mtime = @filemtime($local_path);
         if (!$force_rewrite) {
             $size = @filesize($local_path);
             $ftp_size = @ftp_size($this->_ftp, $remote_file);
             $ftp_mtime = @ftp_mdtm($this->_ftp, $remote_file);
             if ($size === $ftp_size && $mtime === $ftp_mtime) {
                 $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, 'File up-to-date.');
                 continue;
             }
         }
         $result = @ftp_put($this->_ftp, $remote_file, $local_path, FTP_BINARY);
         if ($result) {
             $this->_mdtm($remote_file, $mtime);
             $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, 'OK');
         } else {
             $results[] = $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to upload file (%s).', $this->_get_last_error()));
         }
     }
     $this->_restore_error_handler();
     $this->_disconnect();
     return !$this->_is_error($results);
 }
コード例 #29
0
 /**
  * isdir()
  * Determines if the file is a directory or a file */
 function isdir($file = false)
 {
     if (!$file) {
         $file = $this->pwd();
     }
     if (@ftp_size($this->connection, $file) == '-1') {
         return true;
     } else {
         return false;
     }
     // File
 }
コード例 #30
-5
ファイル: Ftp.class.php プロジェクト: tiger2soft/LycPHP
 /**
  * 下载文件
  * 
  */
 public function download($localfile, $remotefile)
 {
     ftp_set_option($this->ftpobj, FTP_AUTOSEEK, FALSE);
     $res = ftp_nb_get($this->ftpobj, $localfile, $remotefile, $this->mode, ftp_size($this->ftpobj, $localfile));
     while ($res == FTP_MOREDATA) {
         $res = ftp_nb_continue($this->ftpobj);
     }
     if ($res != FTP_FINISHED) {
         return FALSE;
     }
     return TRUE;
 }