Example #1
0
 function mchdir($directory)
 {
     if (!$this->conn_id) {
         return false;
     }
     return @ftp_chdir($this->conn_id, $directory);
 }
Example #2
0
 protected function getConnection()
 {
     if ($this->connection === null) {
         // Connect using FTP
         if ($this->getConnectType() === self::CONNECT_TYPE_FTP) {
             $port = empty($this->getPort()) ? 21 : $this->getPort();
             $this->connection = ftp_connect($this->getHost(), $port);
             if (!$this->connection) {
                 throw new \ErrorException('Failed to connect to FTP');
             }
             if (!ftp_login($this->connection, $this->getUsername(), $this->getPassword())) {
                 throw new \ErrorException('Wrong username/password provided to FTP.');
             }
             if ($this->getStartDirectory()) {
                 if (!ftp_chdir($this->connection, $this->getStartDirectory())) {
                     throw new \ErrorException('Failed to set start directory');
                 }
             }
         } elseif ($this->getConnectType() === self::CONNECT_TYPE_SFTP) {
             $port = empty($this->getPort()) ? 22 : $this->getPort();
             $this->settings = ['host' => $this->getHost(), 'port' => $port, 'username' => $this->getUsername(), 'password' => $this->getPassword(), 'timeout' => 10, 'directoryPerm' => 0755];
             if (!empty($this->getStartDirectory())) {
                 $settings['root'] = $this->getStartDirectory();
             }
             $this->connection = new SftpAdapter($settings);
         } else {
             throw new \ErrorException('Invalid connection-type');
         }
     }
     return $this->connection;
 }
function envia_archivo_via_ftp($cadena, $nombre_archivo_remoto = "", $mensajes = 0)
{
    $fp = fopen("temp.txt", "w");
    if (fwrite($fp, utf8_encode($cadena))) {
        $ftp_sitio = CONFIG("FE_RESPALDO_SITIO");
        $ftp_usuario = CONFIG("FE_RESPALDO_SITIO_USUARIO");
        $ftp_pass = CONFIG("FE_RESPALDO_SITIO_CLAVE");
        $conn = ftp_connect($ftp_sitio) or die("Acceso incorrecto.. " . $ftp_sitio);
        ftp_login($conn, $ftp_usuario, $ftp_pass);
        ftp_chdir($conn, CONFIG("FE_RESPALDO_SITIO_DIR"));
        //echo $ftp_sitio."--".$ftp_usuario."--".$ftp_pass."--".CONFIG("FE_RESPALDO_SITIO_DIR");
        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);
}
Example #4
0
 public function exists($path)
 {
     if (!$this->stream) {
         $this->connectAndLogin();
     }
     $pwd = ftp_pwd($this->stream);
     // try to change directory to see if it is an existing directory
     $result = @ftp_chdir($this->stream, $path);
     if (true === $result) {
         ftp_chdir($this->stream, $pwd);
         // change back to the original directory
         return true;
     } else {
         // list the parent directory and check if the file exists
         $parent = dirname($path);
         $options = '-a';
         // list hidden
         $result = ftp_rawlist($this->stream, $options . ' ' . $parent);
         if (false !== $result) {
             foreach ($result as $line) {
                 if (false !== ($pos = strrpos($line, basename($path)))) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Example #5
0
 public function make_collection($path)
 {
     $path = $this->get_encoded_path($path);
     if (false === ($conn = $this->get_connection_handle())) {
         throw new Exception("Could not connect to FTP server.");
     }
     if ('/' == $path[0]) {
         $path = substr($path, 1);
     }
     if ('/' == substr($path, -1)) {
         $path = substr($path, 0, -1);
     }
     $path_parts = explode('/', $path);
     for ($i = 0; $i < sizeof($path_parts) - 1; $i++) {
         if (false === @ftp_chdir($conn, $path_parts[$i])) {
             $this->throw_exception("Could not change to directory `{$path_parts[$i]}'.");
         }
     }
     $label = $path_parts[sizeof($path_parts) - 1];
     if (false === @ftp_mkdir($conn, $label)) {
         $this->throw_exception("Could not make directory `{$label}'.");
     }
     @ftp_close($conn);
     return true;
 }
function ftpMkDir($path, $newDir, $ftpServer, $ftpUser, $ftpPass)
{
    $server = $ftpServer;
    // ftp server
    $connection = ftp_connect($server);
    // connection
    // login to ftp server
    $user = $ftpUser;
    $pass = $ftpPass;
    $result = ftp_login($connection, $user, $pass);
    // check if connection was made
    if (!$connection || !$result) {
        return false;
        exit;
    } else {
        ftp_chdir($connection, $path);
        // go to destination dir
        if (ftp_mkdir($connection, $newDir)) {
            // create directory
            return $newDir;
        } else {
            return false;
        }
        ftp_close($connection);
        // close connection
    }
}
Example #7
0
function enviaImagen($fRutaImagen, $fDirServ, $fNombreImagen)
{
    $host = 'ftp.laraandalucia.com';
    $usuario = 'laraandalucia.com';
    $pass = '******';
    $errorFtp = 'no';
    $dirServ = 'html/images/Lara/' . $fDirServ;
    $conexion = @ftp_connect($host);
    if ($conexion) {
        if (@ftp_login($conexion, $usuario, $pass)) {
            if (!@ftp_chdir($conexion, $dirServ)) {
                if (!@ftp_mkdir($conexion, $dirServ)) {
                    $errorFtp = 'si';
                }
            }
        } else {
            $errorFtp = 'si';
        }
    } else {
        $errorFtp = 'si';
    }
    if ($errorFtp = 'no') {
        @ftp_chdir($conexion, $dirServ);
        if (@(!ftp_put($conexion, $fNombreImagen, $fRutaImagen, FTP_BINARY))) {
            $errorFtp = 'si';
        }
    }
    @ftp_quit($conexion);
    return $errorFtp == 'no';
}
Example #8
0
 /**
  * Store it locally
  * @param  string $fullPath    Full path from local system being saved
  * @param  string $filename Filename to use on saving
  */
 public function store($fullPath, $filename)
 {
     if ($this->connection == false) {
         $result = array('error' => 1, 'message' => "Unable to connect to ftp server!");
         return $result;
     }
     //prepare dir path to be valid :)
     $this->remoteDir = rtrim($this->remoteDir, "/") . "/";
     try {
         $originalDirectory = ftp_pwd($this->connection);
         // test if you can change directory to remote dir
         // suppress errors in case $dir is not a file or not a directory
         if (@ftp_chdir($this->connection, $this->remoteDir)) {
             // If it is a directory, then change the directory back to the original directory
             ftp_chdir($this->connection, $originalDirectory);
         } else {
             if (!ftp_mkdir($this->connection, $this->remoteDir)) {
                 $result = array('error' => 1, 'message' => "Remote dir does not exist and unable to create it!");
             }
         }
         //save file to local dir
         if (!ftp_put($this->connection, $this->remoteDir . $filename, $fullPath, FTP_BINARY)) {
             $result = array('error' => 1, 'message' => "Unable to send file to ftp server");
             return $result;
         }
         //prepare and return result
         $result = array('storage_path' => $this->remoteDir . $filename);
         return $result;
     } catch (Exception $e) {
         //unable to copy file, return error
         $result = array('error' => 1, 'message' => $e->getMessage());
         return $result;
     }
 }
Example #9
0
 /**
  * Change Directory
  * @param string $dir
  * @return ftp
  *
  */
 public function cd($dir)
 {
     $dir = (string) $dir;
     $dir === '..' ? ftp_cdup($this->ftp) : ftp_chdir($this->ftp, $dir);
     $this->path = $this->pwd();
     return $this;
 }
	/**
	 * Check if the URL is a folder or not
	 * @param $path The file path
	 * @return Boolean
	 */
	public static function isDir($path){
		$chDir = @ftp_chdir(self::$conn, $path);
		if($chDir){
			return TRUE;
		}
		return FALSE;
	}
Example #11
0
 /**
  * Change directories
  *
  * @param  string $dir
  * @throws Exception
  * @return Ftp
  */
 public function chdir($dir)
 {
     if (!ftp_chdir($this->connection, $dir)) {
         throw new Exception('Error: There was an error changing to the directory ' . $dir);
     }
     return $this;
 }
Example #12
0
 private function addDir($dir, $display)
 {
     $chDir = $this->targetDirectory . dirname($dir);
     $mkDir = basename($dir);
     if ($this->testMode) {
         $this->messages[] = "Test mode, Add directory, {$mkDir} to {$chDir}";
         if ($display) {
             echo end($this->messages), "\n";
         }
     } else {
         if (@ftp_chdir($this->conn_id, $chDir) === false) {
             $this->messages[] = "Could not change directory to {$chDir}";
             if ($display) {
                 echo end($this->messages), "\n";
             }
         } else {
             if (($newDir = @ftp_mkdir($this->conn_id, $mkDir)) === false) {
                 $this->messages[] = "Could not Add directory, {$mkDir} to {$chDir}";
                 if ($display) {
                     echo end($this->messages), "\n";
                 }
             } else {
                 $this->messages[] = "Add directory, {$mkDir} to {$chDir}";
                 if ($display) {
                     echo end($this->messages), "\n";
                 }
             }
         }
     }
 }
Example #13
0
 public function getListing()
 {
     $dir = $this->directory;
     // Parse directory to parts
     $parsed_dir = trim($dir, '/');
     $this->parts = empty($parsed_dir) ? array() : explode('/', $parsed_dir);
     // Find the path to the parent directory
     if (!empty($parts)) {
         $copy_of_parts = $parts;
         array_pop($copy_of_parts);
         if (!empty($copy_of_parts)) {
             $this->parent_directory = '/' . implode('/', $copy_of_parts);
         } else {
             $this->parent_directory = '/';
         }
     } else {
         $this->parent_directory = '';
     }
     // Connect to the server
     if ($this->ssl) {
         $con = @ftp_ssl_connect($this->host, $this->port);
     } else {
         $con = @ftp_connect($this->host, $this->port);
     }
     if ($con === false) {
         $this->setError(JText::_('FTPBROWSER_ERROR_HOSTNAME'));
         return false;
     }
     // Login
     $result = @ftp_login($con, $this->username, $this->password);
     if ($result === false) {
         $this->setError(JText::_('FTPBROWSER_ERROR_USERPASS'));
         return false;
     }
     // Set the passive mode -- don't care if it fails, though!
     @ftp_pasv($con, $this->passive);
     // Try to chdir to the specified directory
     if (!empty($dir)) {
         $result = @ftp_chdir($con, $dir);
         if ($result === false) {
             $this->setError(JText::_('FTPBROWSER_ERROR_NOACCESS'));
             return false;
         }
     } else {
         $this->directory = @ftp_pwd($con);
         $parsed_dir = trim($this->directory, '/');
         $this->parts = empty($parsed_dir) ? array() : explode('/', $parsed_dir);
         $this->parent_directory = $this->directory;
     }
     // Get a raw directory listing (hoping it's a UNIX server!)
     $list = @ftp_rawlist($con, '.');
     ftp_close($con);
     if ($list === false) {
         $this->setError(JText::_('FTPBROWSER_ERROR_UNSUPPORTED'));
         return false;
     }
     // Parse the raw listing into an array
     $folders = $this->parse_rawlist($list);
     return $folders;
 }
 /**
  * Connect to ftp server
  *
  * @return bool
  **/
 protected function connect()
 {
     if (!($this->connect = ftp_connect($this->options['host'], $this->options['port'], $this->options['timeout']))) {
         return $this->setError('Unable to connect to FTP server ' . $this->options['host']);
     }
     if (!ftp_login($this->connect, $this->options['user'], $this->options['pass'])) {
         $this->umount();
         return $this->setError('Unable to login into ' . $this->options['host']);
     }
     // switch off extended passive mode - may be usefull for some servers
     //@ftp_exec($this->connect, 'epsv4 off' );
     // enter passive mode if required
     $this->options['mode'] = 'active';
     ftp_pasv($this->connect, $this->options['mode'] == 'passive');
     // enter root folder
     if (!ftp_chdir($this->connect, $this->root)) {
         $this->umount();
         return $this->setError('Unable to open root folder.');
     }
     $stat = array();
     $stat['name'] = $this->root;
     $stat['mime'] = 'directory';
     $this->filesCache[$this->root] = $stat;
     $this->cacheDir($this->root);
     return true;
 }
Example #15
0
 public function ftp($host = '', $user = '', $password = '', $rootdir = './', $port = 21)
 {
     if (defined('C_FTP_METHOD')) {
         $this->_method = C_FTP_METHOD;
     }
     if ($this->_method == 'PHP') {
         //echo 'PHPMODE: ';
         $rootdir = LITO_ROOT_PATH;
         if (!is_dir($rootdir)) {
             return false;
         }
         $this->rootdir = preg_replace('!\\/$!', '', $rootdir);
         $this->connected = true;
         $this->lito_root = true;
         //echo 'Useing PHP as a workaround!';
     } else {
         $this->_host = $host;
         $this->_port = $port;
         $this->_user = $user;
         $this->_password = $password;
         if (!@($this->_connection = ftp_connect($this->_host, $this->_port))) {
             return false;
         }
         if (!@ftp_login($this->_connection, $this->_user, $this->_password)) {
             return false;
         }
         $this->connected = true;
         ftp_chdir($this->_connection, $rootdir);
         //if ($this->exists('litotex.php'))
         $this->lito_root = true;
     }
 }
Example #16
0
function subida_script($ftp_server, $ftp_user, $ftp_pass)
{
    // set up basic connection
    $conn_id = ftp_connect($ftp_server);
    if (!$conn_id) {
        echo "<div class='alert alert-warning' style='width:300px;margin:auto'>Connection established</div>";
    }
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
    if ($login_result) {
        echo "<div class='alert alert-success' style='width:300px;margin:auto'>Connection established</div>";
    }
    ftp_chdir($conn_id, 'public_html');
    ftp_mkdir($conn_id, 'search');
    ftp_chdir($conn_id, 'search');
    ftp_mkdir($conn_id, 'css');
    ftp_chdir($conn_id, 'css');
    echo ftp_pwd($conn_id);
    ftp_chdir($conn_id, '../../autotienda/search');
    echo ftp_pwd($conn_id);
    //Uploading files...
    //to be uploaded
    $file = "search/.htaccess";
    $fp = fopen($file, 'r');
    ftp_fput($conn_id, $file, $fp, FTP_ASCII);
    echo ftp_pwd($conn_id);
    // close the connection
    ftp_close($conn_id);
    fclose($fp);
}
 /**
  * Connect to FTP server and authenticate via password
  *
  * @since 3.0
  * @throws Exception
  * @return \WC_Customer_Order_CSV_Export_Method_FTP
  */
 public function __construct()
 {
     parent::__construct();
     // Handle errors from ftp_* functions that throw warnings for things like invalid username / password, failed directory changes, and failed data connections
     set_error_handler(array($this, 'handle_errors'));
     // setup connection
     $this->link = null;
     if ('ftps' == $this->security && function_exists('ftp_ssl_connect')) {
         $this->link = ftp_ssl_connect($this->server, $this->port, $this->timeout);
     } elseif ('ftps' !== $this->security) {
         $this->link = ftp_connect($this->server, $this->port, $this->timeout);
     }
     // check for successful connection
     if (!$this->link) {
         throw new Exception(__("Could not connect via FTP to {$this->server} on port {$this->port}, check server address and port.", WC_Customer_Order_CSV_Export::TEXT_DOMAIN));
     }
     // attempt to login, note that incorrect credentials throws an E_WARNING PHP error
     if (!ftp_login($this->link, $this->username, $this->password)) {
         throw new Exception(__("Could not authenticate via FTP with username {$this->username} and password <hidden>. Check username and password.", WC_Customer_Order_CSV_Export::TEXT_DOMAIN));
     }
     // set passive mode if enabled
     if ($this->passive_mode) {
         // check for success
         if (!ftp_pasv($this->link, true)) {
             throw new Exception(__('Could not set passive mode', WC_Customer_Order_CSV_Export::TEXT_DOMAIN));
         }
     }
     // change directories if initial path is populated, note that failing to change directory throws an E_WARNING PHP error
     if ($this->path) {
         // check for success
         if (!ftp_chdir($this->link, '/' . $this->path)) {
             throw new Exception(__("Could not change directory to {$this->path} - check path exists.", WC_Customer_Order_CSV_Export::TEXT_DOMAIN));
         }
     }
 }
Example #18
0
 /**
  * Change to the current dir so that operations can be performed relatively
  */
 protected function _changeToDir()
 {
     $chdir = ftp_chdir($this->_ftp->getConnection(), $this->_path);
     if ($chdir === false) {
         //throw new Zend_Ftp_Directory_Exception('Unable to change to directory');
     }
 }
Example #19
0
 function download_file($conn, $ftppath, $prjname)
 {
     $fn = ftp_rawlist($conn, $ftppath);
     //列出该目录的文件名(含子目录),存储在数组中
     foreach ($fn as $file) {
         $b = explode(' ', $file);
         $s = sizeof($b);
         $file = $b[$s - 1];
         if (preg_match('/^[a-zA-Z0-9_]+([a-zA-Z0-9-]*.*)(\\.+)/i', $file)) {
             if (!file_exists($prjname . "/" . $file)) {
                 $fp = fopen($prjname . "/" . $file, "w");
             }
             if (ftp_get($conn, $prjname . "/" . $file, $ftppath . "/" . $file, FTP_BINARY)) {
                 echo "<br/>下载" . $prjname . "/" . $file . "成功<br/>";
             } else {
                 echo "<br/>下载" . $prjname . "/" . $file . "失败<br/>";
             }
         } else {
             if (!file_exists($prjname . "/" . $file)) {
                 echo "新建目录:" . $prjname . "/" . $file . "<br>";
                 mkdir(iconv("UTF-8", "GBK", $prjname . "/" . $file), 0777, true);
                 //本地机器上该目录不存在就创建一个
             }
             if (ftp_chdir($conn, $ftppath . "/" . $file)) {
                 chdir($prjname . "/" . $file);
             }
             $this->download_file($conn, $ftppath . "/" . $file, $prjname . "/" . $file);
             //递归进入该目录下载文件
         }
     }
     //foreach循环结束
     ftp_cdup($conn);
     //ftp服务器返回上层目录
     chdir(dirname($prjname));
 }
Example #20
0
 function listDir($conn, $dirname, $ftpdir)
 {
     $dirs = array();
     $files = array();
     set_time_limit(0);
     $dir = opendir($dirname);
     while (($file = readdir($dir)) != false) {
         if ($file == "." || $file == "..") {
             continue;
         }
         if (is_dir($dirname . "/" . $file)) {
             array_push($dirs, $dirname . "/" . $file);
             //目录不存在,则新建。
             if ($this->isdir($conn, $ftpdir, $file)) {
                 ftp_chdir($conn, $ftpdir);
             } else {
                 ftp_mkdir($conn, $ftpdir . "/" . $file);
                 echo "创建目录---->{$file}---成功! <br/>";
             }
             $this->listDir($conn, $dirname . "/" . $file, $ftpdir . "/" . $file);
         } else {
             array_push($files, $ftpdir . "/" . $file);
             ftp_chdir($conn, $ftpdir);
             if ($this->endsWith($file, ".jpg") || $this->endsWith($file, ".png") || $this->endsWith($file, ".gif") || $this->endsWith($file, ".exe") || $this->endsWith($file, ".zip") || $this->endsWith($file, ".swf") || $this->endsWith($file, ".db") || $this->endsWith($file, ".dll") || $this->endsWith($file, ".PHP") || $this->endsWith($file, ".INI") || $this->endsWith($file, ".js") || $this->endsWith($file, ".css") || $this->endsWith($file, ".zip") || $this->endsWith($file, ".rar") || $this->endsWith($file, ".xml") || $this->endsWith($file, ".html") || $this->endsWith($file, ".doc") || $this->endsWith($file, ".TXT")) {
                 $upload = ftp_put($conn, $file, $dirname . "/" . $file, FTP_BINARY);
             } else {
                 $upload = ftp_put($conn, $file, $dirname . "/" . $file, FTP_ASCII);
                 echo "上传文件--->{$dirname}/{$file} ------成功! <br/>";
             }
         }
     }
 }
function syncFolderToFtp($host, $username, $password, $remote_backup, $backup_folder)
{
    $ftp = ftp_connect($host);
    // connect to the ftp server
    ftp_login($ftp, $username, $password);
    // login to the ftp server
    ftp_chdir($ftp, $remote_backup);
    // cd into the remote backup folder
    // copy files from folder to remote folder
    $files = glob($backup_folder . '*');
    $c = 0;
    $allc = count($files);
    foreach ($files as $file) {
        $c++;
        $file_name = basename($file);
        echo "\n {$c}/{$allc}: {$file_name}";
        $upload = ftp_nb_put($ftp, $file_name, $file, FTP_BINARY);
        // non-blocking put, uploads the local backup onto the remote server
        while ($upload == FTP_MOREDATA) {
            // Continue uploading...
            $upload = ftp_nb_continue($ftp);
        }
        if ($upload != FTP_FINISHED) {
            echo " ... ERROR";
        } else {
            echo " ... OK";
        }
    }
    ftp_close($ftp);
    // closes the connection
}
Example #22
0
function ftp_sync($dir)
{
    global $conn_id;
    if ($dir != ".") {
        if (ftp_chdir($conn_id, $dir) == false) {
            echo "Change Dir Failed: {$dir}<BR>\r\n";
            return;
        }
        if (!is_dir($dir)) {
            mkdir($dir);
        }
        chdir($dir);
    }
    $contents = ftp_nlist($conn_id, ".");
    foreach ($contents as $file) {
        if ($file == '.' || $file == '..') {
            continue;
        }
        if (@ftp_chdir($conn_id, $file)) {
            ftp_chdir($conn_id, "..");
            ftp_sync($file);
        } else {
            ftp_get($conn_id, $file, $file, FTP_BINARY);
        }
    }
    ftp_chdir($conn_id, "..");
    chdir("..");
}
Example #23
0
 static function ftp_check_dir($remote_dir_path, $mkdir = true)
 {
     $ret = true;
     if (self::ftp_image_connect()) {
         if ($remote_dir_path == '') {
             return true;
         }
         $dir = split("/", $remote_dir_path);
         $remote_dir_path = "";
         for ($i = 0; $i < count($dir); $i++) {
             if ($dir[$i] != '') {
                 $remote_dir_path .= "/" . $dir[$i];
                 if (!@ftp_chdir(ImageLib::$ftp_image_connect_id, $remote_dir_path)) {
                     if ($mkdir) {
                         @ftp_chdir(ImageLib::$ftp_image_connect_id, "/");
                         if (!@ftp_mkdir(ImageLib::$ftp_image_connect_id, $remote_dir_path)) {
                             $ret = false;
                             break;
                         }
                     } else {
                         $ret = false;
                         break;
                     }
                 }
             }
         }
         @ftp_chdir(ImageLib::$ftp_image_connect_id, "/");
     } else {
         $ret = false;
     }
     return $ret;
 }
Example #24
0
 /**
  * Function that retrieves a file from FTP library and compress it if necessary
  * 
  * @param string $file File name to be retrieved from FTP library
  * @return boolean
  */
 public function get_file($file, $dir = '')
 {
     if (!defined("LOCATION") || !defined("CODE") || !defined("LIBRARY") || !defined("CACHE_PATH")) {
         $this->container->__error("Imposible recuperar el archivo remoto: falta alguna constante por definir");
         return false;
     }
     $cnn = ftp_connect(LOCATION);
     $rs = ftp_login($cnn, LIBRARY, CODE);
     if ($rs === false) {
         $this->container->__error("Imposible conectar a la libreria de funciones!");
     }
     $dir = $dir == '' ? '' : $dir . DIRECTORY_SEPARATOR;
     ftp_chdir($cnn, LIBRARY . DIRECTORY_SEPARATOR . $dir);
     if (@ftp_chdir($cnn, $file) !== false) {
         if ($this->container->__debug()) {
             @mkdir(CACHE_PATH . $dir . $file);
             chmod(CACHE_PATH . $dir . $file, 0777);
             $dir = $dir == '' ? $file : $dir . $file;
         } else {
             @mkdir(CACHE_PATH . $dir . md5($file));
             chmod(CACHE_PATH . $dir . md5($file), 0777);
             $dir = $dir == '' ? $file : $dir . $file;
         }
         $files = ftp_nlist($cnn, ".");
         foreach ($files as $filea) {
             $this->get_file($filea, $dir);
         }
         return true;
     } else {
         if ($file == '.' || $file == '..') {
             return;
         }
         if ($this->container->__debug()) {
             $aux = ftp_get($cnn, CACHE_PATH . $dir . $file, $file, FTP_BINARY);
         } else {
             $temp = explode(DIRECTORY_SEPARATOR, $dir);
             array_walk($temp, function (&$element, $index) {
                 $element = md5($element);
             });
             array_pop($temp);
             $temp = implode(DIRECTORY_SEPARATOR, $temp) . DIRECTORY_SEPARATOR;
             $aux = ftp_get($cnn, CACHE_PATH . $temp . md5($file), $file, FTP_BINARY);
         }
         if (!$aux) {
             ftp_close($cnn);
             $this->container->__error("Imposible obtener el archivo para cache: " . $file);
             return false;
         } else {
             ftp_close($cnn);
             if ($this->container->__debug()) {
                 chmod(CACHE_PATH . $dir . $file, 0777);
                 $this->compress_cache_file($dir . $file);
             } else {
                 chmod(CACHE_PATH . $temp . md5($file), 0777);
                 $this->compress_cache_file($temp . md5($file));
             }
             return true;
         }
     }
 }
Example #25
0
 /**
  * @return resource
  */
 protected function getFtpConnection()
 {
     $ftp = ftp_connect(Mage::getStoreConfig(self::XML_PATH_FTP_HOSTNAME), Mage::getStoreConfig(self::XML_PATH_FTP_PORT));
     ftp_login($ftp, Mage::getStoreConfig(self::XML_PATH_FTP_USERNAME), Mage::getStoreConfig(self::XML_PATH_FTP_PASSWORD));
     ftp_pasv($ftp, true);
     ftp_chdir($ftp, Mage::getStoreConfig(self::XML_PATH_FTP_ROOTPATH));
     return $ftp;
 }
Example #26
0
 public function opendir($dir)
 {
     if (FALSE === ftp_chdir($this->link, $dir)) {
         $this->errormsg = "Can't change this dir";
         return FALSE;
     }
     return TRUE;
 }
Example #27
0
 public function changeFolder(string $path) : bool
 {
     if (ftp_chdir($this->connect, $path)) {
         return true;
     } else {
         throw new FolderChangeDirException($path);
     }
 }
Example #28
0
 function chdir($dir)
 {
     if (!ftp_chdir($this->ftp_conn, $dir)) {
         $this->error[] = "Could not change directory to {$dir}";
         return false;
     }
     return true;
 }
Example #29
0
 public function __construct($host, $user, $pass, $dir)
 {
     if (!($this->ftp = ftp_connect($host))) {
         throw new Exception('Could not Connect do FTP Host');
     }
     ftp_login($this->ftp, $user, $pass);
     ftp_chdir($this->ftp, $dir);
 }
Example #30
0
function deleteimg($img)
{
    $imgd = $img;
    $conn = ftp_connect("localhost");
    ftp_login($conn, "root", "sandy");
    ftp_chdir($conn, "dj/images");
    echo ftp_delete($conn, "{$imgd}.jpg");
    ftp_close($conn);
}