public function connect() { $this->printLog("Connect"); if ($this->conn_id = ftp_connect($this->host, $this->port, $this->timeout)) { if (ftp_login($this->conn_id, $this->user, $this->pass)) { $this->updateState(PR_FTP_STATE_LOGGED_IN); if ($status = ftp_chdir($this->conn_id, $this->cur_path)) { $this->updateState(PR_FTP_STATE_TARGETED); $this->updateStatus(PR_FTP_STATUS_READY); $this->systype = ftp_systype($this->conn_id); // TODO: make specific OS dependednt things $this->printLog("OS: " . $this->systype . " " . ftp_pwd($this->conn_id)); // TODO: pass the mode into the module ftp_pasv($this->conn_id, true); unset($this->listing_cache); $this->listing_cache = array(); } else { $this->updateState(PR_FTP_STATE_ERROR); } } else { $this->updateState(PR_FTP_STATE_DISCONNECTED); $this->updateStatus(PR_FTP_STATUS_NOT_READY); } } else { $this->updateState(PR_FTP_STATE_DISCONNECTED); $this->updateStatus(PR_FTP_STATUS_NOT_READY); } }
function pwd() { $this->login(); $dir = ftp_pwd($this->link_id); $this->dir = $dir; return $dir; }
/** * Magic method (do not call directly). * @param string method name * @param array arguments * @return mixed * @throws MemberAccessException * @throws FtpException */ public function __call($name, $args) { $name = strtolower($name); $silent = strncmp($name, 'try', 3) === 0; $func = $silent ? substr($name, 3) : $name; static $aliases = array('sslconnect' => 'ssl_connect', 'getoption' => 'get_option', 'setoption' => 'set_option', 'nbcontinue' => 'nb_continue', 'nbfget' => 'nb_fget', 'nbfput' => 'nb_fput', 'nbget' => 'nb_get', 'nbput' => 'nb_put'); $func = 'ftp_' . (isset($aliases[$func]) ? $aliases[$func] : $func); if (!function_exists($func)) { return parent::__call($name, $args); } Tools::tryError(); if ($func === 'ftp_connect' || $func === 'ftp_ssl_connect') { $this->state = array($name => $args); $this->resource = call_user_func_array($func, $args); $res = NULL; } elseif (!is_resource($this->resource)) { Tools::catchError($msg); throw new FtpException("Not connected to FTP server. Call connect() or ssl_connect() first."); } else { if ($func === 'ftp_login' || $func === 'ftp_pasv') { $this->state[$name] = $args; } array_unshift($args, $this->resource); $res = call_user_func_array($func, $args); if ($func === 'ftp_chdir' || $func === 'ftp_cdup') { $this->state['chdir'] = array(ftp_pwd($this->resource)); } } if (Tools::catchError($msg) && !$silent) { throw new FtpException($msg); } return $res; }
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; }
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; }
/** * 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; } }
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); }
/** * Récupère la liste des fichiers en fonction du pointeur * * @require class FileFolder * * @param string $path -> Le chemin du répertoire à lister * @param array $hidden_folders -> Les dossiers à masquer : array('dossier1', 'dossier2); * @param array $hidden_files -> Les fichiers ou extension à masquer : array('Thumbs.db', 'index.php', 'exe'); * @return array ['path'], ['folders'], ['files'] */ public static function getFiles($path = null, $hidden_folders = array(), $hidden_files = array()) { // Si la class FileFolder est instanciée if (class_exists('FileFolder')) { // Initialisation $out = array('path' => null, 'folders' => null, 'files' => null); $link = self::connection(); // Si la connexion à réussie if (is_resource($link)) { // Si aucun chemin n'est spécifié, on récupère le dossier courant if ($path == null) { $path = @ftp_pwd($link); } $out['path'] = $path; // Liste des fichiers $files = ftp_rawlist($link, $path); if (count($files) > 0) { foreach ($files as $file) { // Parse $data = preg_split("#[\\s]+#", $file, 9); // Si c'est un dossier if ($data[0][0] === 'd') { // Si le dossier n'est pas parmi les dossiers masqués if ($data[8] != '.' && $data[8] != '..' && !in_array($data[8], $hidden_folders)) { $out['folders'][$data[8]]['items'] = $data[1]; $out['folders'][$data[8]]['mtime'] = date('d/m/Y H:i:s', strtotime($data[5] . ' ' . $data[6] . ' ' . $data[7])); $out['folders'][$data[8]]['chmod'] = $data[0]; $out['folders'][$data[8]]['user'] = $data[2]; $out['folders'][$data[8]]['group'] = $data[3]; } } else { // Si c'est un fichier different des fichiers masqués if (!in_array($data[8], $hidden_files)) { // Si le fichier est différent d'une extension masquée if (!in_array(FileFolder::getFilenameExtension($data[8]), $hidden_files)) { $out['files'][$data[8]]['size'] = FileFolder::formatSize($data[4]); $out['files'][$data[8]]['ext'] = FileFolder::getFilenameExtension($data[8]); $out['files'][$data[8]]['type'] = FileFolder::getFileType($data[8]); $out['files'][$data[8]]['mtime'] = date('d/m/Y H:i:s', strtotime($data[5] . ' ' . $data[6] . ' ' . $data[7])); $out['files'][$data[8]]['chmod'] = $data[0]; $out['files'][$data[8]]['user'] = $data[2]; $out['files'][$data[8]]['group'] = $data[3]; } } } } } // Déconnexion self::disconnection($link); // Retour return $out; } else { return $link; } } else { return 'class FileFolder no exists'; } }
public static function CheckDir($dirname, $conn) { $origin = ftp_pwd($conn); if (@ftp_chdir($conn, $dirname)) { ftp_chdir($conn, $origin); return ftp_nlist($conn, $dirname); } return false; }
/** * Get current directory */ public function pwd() { Logger::log('pwd '); $result = ftp_pwd($this->connectionId); if (empty($result)) { Logger::log('pwd command return false'); } return $result; }
function ftp_is_dir($ftp, $dir) { $pushd = ftp_pwd($ftp); if ($pushd !== false && @ftp_chdir($ftp, $dir)) { ftp_chdir($ftp, $pushd); return true; } return false; }
/** * Vérifie si le chemin pointe sur un fichier sur le serveur. * * @param string $dirname * @return bool */ public function isDirectory($dirname) { $tmp = ftp_pwd($this->ftp); $r = false; if (ftp_chdir($this->ftp, $dirname)) { $r = true; ftp_chdir($this->ftp, $tmp); } return $r; }
function ftp_is_dir($ftp_stream, $dir) { $original_directory = ftp_pwd($ftp_stream); if (@ftp_chdir($ftp_stream, $dir)) { ftp_chdir($ftp_stream, $original_directory); return true; } else { return false; } }
public function is_dir($strPath) { $origin = @ftp_pwd($this->objFTP); if (@ftp_chdir($this->objFTP, $strPath)) { ftp_chdir($this->objFTP, $origin); return true; } else { return false; } }
public function ftp_is_dir($dir) { $orig_rid = ftp_pwd($this->ftp_conn); if (@ftp_chdir($this->ftp_conn, $dir)) { ftp_chdir($this->ftp_conn, $orig_rid); return true; } else { return false; } }
/** * {@inheritdoc} */ public function isDirectory($path) { $result = FALSE; $curr = ftp_pwd($this->connection); if (@ftp_chdir($this->connection, $path)) { $result = TRUE; } ftp_chdir($this->connection, $curr); return $result; }
public function changeDir($directory) { if (ftp_chdir($this->connectionId, $directory)) { $this->logMessage('Current directory is now: ' . ftp_pwd($this->connectionId)); return true; } else { $this->logMessage('Couldn\'t change directory'); return false; } }
/** * 检测上传根目录 * @param string $rootpath 根目录 * @return boolean true-检测通过,false-检测失败 */ public function checkRootPath($rootpath) { /* 设置根目录 */ $this->rootPath = ftp_pwd($this->link) . '/' . ltrim($rootpath, '/'); if (!@ftp_chdir($this->link, $this->rootPath)) { $this->error = '上传根目录不存在!'; return false; } return true; }
public function changeDir($directory) { if (ftp_chdir($this->connectionId, $directory)) { $this->logMessage('Þu anda baðlý olunan klasör: ' . ftp_pwd($this->connectionId)); return true; } else { $this->logMessage('Klasör deðiþtirilemedi'); return false; } }
public function pwd() { if (!is_resource($this->resource)) { throw new ConnectionException('Connection is not open'); } if (false !== ($pwd = @ftp_pwd($this->resource))) { return $pwd; } else { throw new ConnectionException('Unable to get working directory'); } }
/** * 构造函数,用于设置上传根路径 * @param string $root 根目录 * @param array $config FTP配置 */ public function __construct($root, $config) { /* 默认FTP配置 */ $this->config = array_merge($this->config, $config); /* 登录FTP服务器 */ if (!$this->login()) { throw new \Exception($this->error); } /* 设置根目录 */ $this->rootPath = ftp_pwd($this->link) . '/' . ltrim($root, '/'); }
function ObtenerRuta($servidor, $puerto, $usuario, $password) { //Obtiene ruta del directorio del Servidor FTP (Comando ftp_pwd) $id_ftp = ConectarFTP($servidor, $puerto, $usuario, $password); //Obtiene un manejador y se conecta al Servidor FTP $Directorio = @ftp_pwd($id_ftp); //Devuelve ruta actual @ftp_quit($id_ftp); //Cierra la conexion FTP return $Directorio; //Devuelve la ruta a la función }
function ObtenerRuta() { //Obriene ruta del directorio del Servidor FTP (Comando PWD) $id_ftp = ConectarFTP(); //Obtiene un manejador y se conecta al Servidor FTP $Directorio = ftp_pwd($id_ftp); //Devuelve ruta ftp_quit($id_ftp); //Cierra la conexion FTP return $Directorio; //Devuelve la ruta a la función }
function ftp_is_dir($ftp_stream, $path) { $cwd = @ftp_pwd($ftp_stream); if ($cwd !== false) { $isdir = @ftp_chdir($ftp_stream, $path); if ($isdir) { ftp_chdir($ftp_stream, $cwd); return true; } } return false; }
/** * Returns the url for file * By default absolute path to file is returned * Otherwise when $options array contain key `relative` set as true, relative path will be returned * * @param $key * @param array $options * @return mixed */ public function getUrl($key, array $options = []) { $absolutePathPattern = ':protocol://:username@:host:pwd/:directory/:file'; $protocol = $this->ssl ? 'ftps' : 'ftp'; $pwd = ftp_pwd($this->connection); $url = strtr($absolutePathPattern, [':protocol' => $protocol, ':username' => $this->username, ':host' => $this->host, ':pwd' => $pwd, ':directory' => $this->directory, ':file' => $key]); if (isset($options['relative']) && $options['relative']) { $relativePathPattern = ':pwd/:directory/:file'; $url = strtr($relativePathPattern, [':pwd' => $pwd, ':directory' => $this->directory, ':file' => $key]); } return Path::normalize($url); }
protected function setConnectionRoot() { $connection = $this->getConnection(); if ($this->root && !ftp_chdir($connection, $this->getRoot())) { throw new RuntimeException('Root is invalid or does not exist: ' . $this->getRoot()); } // Store absolute path for further reference. // This is needed when creating directories and // initial root was a relative path, else the root // would be relative to the chdir'd path. $this->root = ftp_pwd($connection); }
function ls($dir) { $f = empty($this->conf['ls_flags']) ? '' : $this->conf['ls_flags'] . ' '; if (isset($this->conf['space_in_filename_workaround']) && $this->conf['space_in_filename_workaround']) { $pwd = @ftp_pwd($this->cid); @ftp_chdir($this->cid, $dir); $list = @ftp_rawlist($this->cid, $f . '.'); @ftp_chdir($this->cid, $pwd); } else { $list = ftp_rawlist($this->cid, $f . $dir); } return $list; }
function ftp_is_dir($dir) { global $ftp_conn; // get current directory $original_directory = ftp_pwd($ftp_conn); // test if you can change directory to $dir // suppress errors in case $dir is not a file or not a directory if (@ftp_chdir($ftp_conn, $dir)) { // If it is a directory, then change the directory back to the original directory ftp_chdir($ftp_conn, $original_directory); return true; } else { return false; } }
/** * Uploads files to FTP * * @param array $files * @param array $results * @return boolean */ function upload($files, &$results) { $count = 0; $error = null; if (!$this->_connect($error)) { $results = $this->get_results($files, W3_CDN_RESULT_HALT, $error); return false; } $home = @ftp_pwd($this->_ftp); foreach ($files as $local_path => $remote_path) { if (!file_exists($local_path)) { $results[] = $this->get_result($local_path, $remote_path, W3_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)) { @ftp_close($this->_ftp); $results[] = $this->get_result($local_path, $remote_path, W3_CDN_RESULT_ERROR, 'Unable to create directory'); continue; } @ftp_chmod($this->_ftp, 0755, $dir); if (!@ftp_chdir($this->_ftp, $dir)) { @ftp_close($this->_ftp); $results[] = $this->get_result($local_path, $remote_path, W3_CDN_RESULT_ERROR, 'Unable to change directory'); continue; } } } $remote_file = basename($remote_path); if (@ftp_size($this->_ftp, $remote_file) == filesize($local_path)) { $results[] = $this->get_result($local_path, $remote_path, W3_CDN_RESULT_ERROR, 'File already exists'); continue; } $result = @ftp_put($this->_ftp, $remote_file, $local_path, FTP_BINARY); $results[] = $this->get_result($local_path, $remote_path, $result ? W3_CDN_RESULT_OK : W3_CDN_RESULT_ERROR, $result ? 'OK' : 'Unable to upload file'); if ($result) { $count++; @ftp_chmod($this->_ftp, 0644, $remote_file); } } $this->_disconnect(); return $count; }
/** * This takes the path we're attempting to save to, and the last element of the path. * (This should not be overwritten, it's populated in successive traversal) */ private function _FTPCreatePath($path, $last = array()) { if (!@ftp_chdir($this->connection, $path)) { $last[] = Xend_Path::getLastPathComponent($path); $path = Xend_Path::stripLastPathComponent($path); $this->_FTPCreatePath($path, $last); } else { if ($last) { $last = array_reverse($last); foreach ($last as $dir) { if (!ftp_mkdir($this->connection, $dir) || !ftp_chdir($this->connection, ftp_pwd($this->connection) . '/' . $dir)) { require_once 'Newstool/Image/Processor/Exception.php'; throw new Newstool_Image_Processor_Exception("Could not create directory for saving."); } } } } }