示例#1
0
文件: ftp.php 项目: shgysk8zer0/core
 /**
  * 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;
 }
示例#2
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));
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 protected function removeDirectoryJailed($directory)
 {
     $pwd = ftp_pwd($this->connection);
     if (!ftp_chdir($this->connection, $directory)) {
         throw new FileTransferException("Unable to change to directory @directory", NULL, array('@directory' => $directory));
     }
     $list = @ftp_nlist($this->connection, '.');
     if (!$list) {
         $list = array();
     }
     foreach ($list as $item) {
         if ($item == '.' || $item == '..') {
             continue;
         }
         if (@ftp_chdir($this->connection, $item)) {
             ftp_cdup($this->connection);
             $this->removeDirectory(ftp_pwd($this->connection) . '/' . $item);
         } else {
             $this->removeFile(ftp_pwd($this->connection) . '/' . $item);
         }
     }
     ftp_chdir($this->connection, $pwd);
     if (!ftp_rmdir($this->connection, $directory)) {
         throw new FileTransferException("Unable to remove to directory @directory", NULL, array('@directory' => $directory));
     }
 }
示例#4
0
文件: ftp.php 项目: a195474368/ejw
 function cdup()
 {
     $this->login();
     $isok = ftp_cdup($this->link_id);
     if ($isok) {
         $this->dir = $this->pwd();
     }
     return $isok;
 }
示例#5
0
function copy_file_to_ftp($idhash, $year, $month)
{
    global $con;
    // Returning to root path
    ftp_cdup($con);
    ftp_cdup($con);
    // Check existing directory of year
    navigate_to_dir($year);
    // Check existing directory of month
    navigate_to_dir($month);
    // Copy file
    $res = ftp_put($con, '/' . $year . '/' . $month . '/' . $idhash, IMGS_PATH . $idhash, FTP_BINARY);
    if (!$res) {
        // We in cycle for upload few images - if got error - we'll continue, message only
        $err = error_get_last();
        printf("Could not upload file %s\r\n%s\r\n", $idhash, $err["message"]);
        return false;
    }
    return true;
}
示例#6
0
 /**
  * 方法:生成目录
  * @path -- 路径
  */
 function dir_mkdirs($path)
 {
     $path_arr = explode('/', $path);
     // 取目录数组
     $file_name = array_pop($path_arr);
     // 弹出文件名
     $path_div = count($path_arr);
     // 取层数
     foreach ($path_arr as $val) {
         if (@ftp_chdir($this->conn_id, $val) == FALSE) {
             $tmp = @ftp_mkdir($this->conn_id, $val);
             if ($tmp == FALSE) {
                 echo "目录创建失败,请检查权限及路径是否正确!";
                 exit;
             }
             @ftp_chdir($this->conn_id, $val);
         }
     }
     for ($i = 1; $i = $path_div; $i++) {
         @ftp_cdup($this->conn_id);
     }
 }
示例#7
0
文件: ftp.php 项目: Nolfneo/docvert
function copyFileViaFtp($sourcePath, $destinationPath, $connectionId)
{
    $errorMessage = '';
    $sourcePath = str_replace(" ", "-", $sourcePath);
    $destinationPath = sanitiseFtpPath($destinationPath);
    if (@(!ftp_mkdir($connectionId, $destinationPath))) {
        $errorMessage .= "&error-ftp-unable-to-create-directory; " . $destinationPath . "\n";
    }
    @ftp_site($connectionId, 'CHMOD 0777 ' . $destinationPath);
    // non-Unix-based servers may respond with "Command not implemented for that parameter" as they don't support chmod, so don't display any errors of this command.
    ftp_chdir($connectionId, $destinationPath);
    //print $sourcePath.' to '.$destinationPath."<br />";
    if (is_dir($sourcePath)) {
        chdir($sourcePath);
        $handle = opendir('.');
        while (($file = readdir($handle)) !== false) {
            if ($file != "." && $file != "..") {
                if (is_dir($file)) {
                    $errorMessage .= copyFileViaFtp($sourcePath . DIRECTORY_SEPARATOR . $file, $file, $connectionId);
                    chdir($sourcePath);
                    if (!ftp_cdup($connectionId)) {
                        $errorMessage .= '&error-unable-ftp-cd-up;';
                    }
                } else {
                    if (substr($file, strlen($file) - 4, 4) != '.zip') {
                        $fp = fopen($file, 'r');
                        if (!ftp_fput($connectionId, sanitiseFtpPath($file), $fp, FTP_BINARY)) {
                            $errorMessage .= '&error-unable-ftp-fput;';
                        }
                        @ftp_site($connectionId, 'CHMOD 0755 ' . sanitiseFtpPath($file));
                        fclose($fp);
                    }
                }
            }
        }
        closedir($handle);
    }
    return $errorMessage;
}
示例#8
0
function ftp_myexec2($ftp, $list)
{
    global $ftp_log, $ftp_error, $lang;
    // getting current directory
    $root_dir = @ftp_pwd($ftp);
    if ($root_dir === false) {
        $ftp_log[] = $ftp_error = $lang['xs_ftp_log_nopwd'];
        return false;
    }
    $current_dir = strlen($root_dir) ? $root_dir . '/' : '';
    // run commands
    for ($i = 0; $i < count($list); $i++) {
        $item = $list[$i];
        if ($item['command'] == 'mkdir') {
            // create new directory
            $res = @ftp_mkdir($ftp, $item['dir']);
            if (!$res) {
                $ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_nomkdir']);
                if (empty($item['ignore'])) {
                    return false;
                }
            } else {
                $ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_mkdir']);
            }
        } elseif ($item['command'] == 'chdir') {
            // change current directory
            $res = @ftp_chdir($ftp, $item['dir']);
            if (!$res) {
                $ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_nochdir']);
                if (empty($item['ignore'])) {
                    return false;
                }
            } else {
                $ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_chdir']);
            }
        } elseif ($item['command'] == 'cdup') {
            // change current directory
            $res = @ftp_cdup($ftp);
            if (!$res) {
                $ftp_log[] = $ftp_error = str_replace('{DIR}', '..', $lang['xs_ftp_log_nochdir']);
                if (empty($item['ignore'])) {
                    return false;
                }
            } else {
                $ftp_log[] = str_replace('{DIR}', '..', $lang['xs_ftp_log_chdir']);
            }
        } elseif ($item['command'] == 'rmdir') {
            // remove directory
            $res = @ftp_rmdir($ftp, $item['dir']);
            if (!$res) {
                $ftp_log[] = $ftp_error = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_normdir']);
                if (empty($item['ignore'])) {
                    return false;
                }
            } else {
                $ftp_log[] = str_replace('{DIR}', $item['dir'], $lang['xs_ftp_log_rmdir']);
            }
        } elseif ($item['command'] == 'upload') {
            // upload file
            $res = @ftp_put($ftp, $current_dir . $item['remote'], $item['local'], FTP_BINARY);
            if (!$res) {
                $ftp_log[] = $ftp_error = str_replace('{FILE}', $item['remote'], $lang['xs_ftp_log_noupload']);
                if (empty($item['ignore'])) {
                    return false;
                }
            } else {
                $ftp_log[] = str_replace('{FILE}', $item['remote'], $lang['xs_ftp_log_upload']);
            }
        } elseif ($item['command'] == 'chmod') {
            // upload file
            $res = @ftp_chmod($ftp, $item['mode'], $current_dir . $item['file']);
            if (!$res) {
                $ftp_log[] = str_replace('{FILE}', $item['file'], $lang['xs_ftp_log_nochmod']);
                if (empty($item['ignore'])) {
                    return false;
                }
            } else {
                $ftp_log[] = str_replace(array('{FILE}', '{MODE}'), array($item['file'], $item['mode']), $lang['xs_ftp_log_chmod']);
            }
        } elseif ($item['command'] == 'exec') {
            $res = ftp_myexec2($ftp, $item['list']);
            if (!$res) {
                return false;
            }
        } elseif ($item['command'] == 'removeall') {
            ftp_remove_all($ftp);
        } else {
            $ftp_log[] = str_replace('{COMMAND}', $item['command'], $lang['xs_ftp_log_invalidcommand']);
            if (empty($item['ignore'])) {
                return false;
            }
        }
    }
    // changing current directory back
    $ftp_log[] = str_replace('{DIR}', $root_dir, $lang['xs_ftp_log_chdir2']);
    if (!@ftp_chdir($ftp, $root_dir)) {
        $ftp_log[] = $ftp_error = str_replace('{DIR}', $root_dir, $lang['xs_ftp_log_nochdir2']);
        return false;
    }
    return true;
}
 /**
  * Change Directory
  *
  * @param	string		$dir		New directory
  * @return	@e void
  * @throws	Exception	CHDIR_FAILED
  */
 public function chdir($dir)
 {
     if ($dir == '..') {
         $currentDir = @ftp_pwd($this->stream);
         $chdir = @ftp_cdup($this->stream);
         if ($currentDir === @ftp_pwd($this->stream)) {
             $chdir = false;
         }
     } elseif (substr($dir, 0, 1) !== '/') {
         $dir = $this->directory . '/' . $dir;
         $chdir = @ftp_chdir($this->stream, $dir);
     } else {
         $chdir = @ftp_chdir($this->stream, $dir);
     }
     if (!$chdir) {
         throw new Exception('CHDIR_FAILED');
     }
     $this->directory = @ftp_pwd($this->stream);
 }
示例#10
0
 /**
  * Changes to the parent directory on the remote FTP server.
  *
  * @return	boolean
  */
 public function parentDir()
 {
     if ($this->getActive()) {
         // Move up!
         if (ftp_cdup($this->_connection)) {
             return true;
         } else {
             return false;
         }
     } else {
         throw new CDbException('EFtpComponent is inactive and cannot perform any FTP operations.');
     }
 }
示例#11
0
 /**
  * Tests FTP server
  *
  * @param string $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $rand = md5(time());
     $tmp_dir = 'test_dir_' . $rand;
     $tmp_file = 'test_file_' . $rand;
     $tmp_path = W3TC_CACHE_TMP_DIR . '/' . $tmp_file;
     if (!@file_put_contents($tmp_path, $rand)) {
         $error = sprintf('Unable to create file: %s.', $tmp_path);
         return false;
     }
     if (!$this->_connect($error)) {
         return false;
     }
     $this->_set_error_handler();
     if (!@ftp_mkdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to make directory: %s (%s).', $tmp_dir, $this->_get_last_error());
         @unlink($tmp_path);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (file_exists($this->_config['docroot'] . '/' . $tmp_dir)) {
         $error = sprintf('Test directory was made in your site root, not on separate FTP host or path. Change path or FTP information: %s.', $tmp_dir);
         @unlink($tmp_path);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (!@ftp_chdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to change directory to: %s (%s).', $tmp_dir, $this->_get_last_error());
         @unlink($tmp_path);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (!@ftp_put($this->_ftp, $tmp_file, $tmp_path, FTP_BINARY)) {
         $error = sprintf('Unable to upload file: %s (%s).', $tmp_path, $this->_get_last_error());
         @unlink($tmp_path);
         @ftp_cdup($this->_ftp);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     @unlink($tmp_path);
     if (!@ftp_delete($this->_ftp, $tmp_file)) {
         $error = sprintf('Unable to delete file: %s (%s).', $tmp_path, $this->_get_last_error());
         @ftp_cdup($this->_ftp);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     @ftp_cdup($this->_ftp);
     if (!@ftp_rmdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to remove directory: %s (%s).', $tmp_dir, $this->_get_last_error());
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     $this->_restore_error_handler();
     $this->_disconnect();
     return true;
 }
示例#12
0
 /**
  * 目录生成(支持递归)
  *
  * @access 	public
  * @param 	string 	目录标识(ftp)
  * @return	boolean
  */
 public function mkdir($path = '', $permissions = NULL)
 {
     if ($path == '' or !$this->_isconn()) {
         return FALSE;
     }
     if ($path[strlen($path) - 1] != '/') {
         $path .= '/';
     }
     $path_arr = explode('/', $path);
     // 取目录数组
     $file_name = array_pop($path_arr);
     // 弹出文件名
     $path_div = count($path_arr);
     // 取层数
     foreach ($path_arr as $val) {
         if (@ftp_chdir($this->conn_id, $val) == FALSE) {
             $result = @ftp_mkdir($this->conn_id, $val);
             if ($result == FALSE) {
                 if ($this->debug === TRUE) {
                     $this->_error("ftp_unable_to_mkdir:dir[" . $path . "]");
                 }
                 return FALSE;
             }
             @ftp_chdir($this->conn_id, $val);
         }
     }
     for ($i = 1; $i <= $path_div; $i++) {
         @ftp_cdup($this->conn_id);
     }
     if (!is_null($permissions)) {
         $this->chmod($path, (int) $permissions);
     }
     return TRUE;
 }
示例#13
0
function deleteFolder($folder, $path)
{
    global $conn_id;
    global $lang_cant_delete;
    global $lang_folder_doesnt_exist;
    global $lang_folder_cant_delete;
    $isError = 0;
    // List contents of folder
    if ($path != "/" && $path != "~") {
        $folder_path = $path . "/" . $folder;
    } else {
        if ($_SESSION["win_lin"] == "lin" || $_SESSION["win_lin"] == "mac") {
            if ($_SESSION["dir_current"] == "/") {
                $folder_path = "/" . $folder;
            }
        }
        if ($_SESSION["dir_current"] == "~") {
            $folder_path = "~/" . $folder;
        }
        if ($_SESSION["win_lin"] == "win") {
            $folder_path = "/" . $folder;
        }
    }
    $ftp_rawlist = getFtpRawList($folder_path);
    // Go through array of files/folders
    if (sizeof($ftp_rawlist) > 0) {
        $count = 0;
        foreach ($ftp_rawlist as $ff) {
            $count++;
            // Split up array into values (Lin)
            if ($_SESSION["win_lin"] == "lin") {
                $ff = preg_split("/[\\s]+/", $ff, 9);
                $perms = $ff[0];
                $file = $ff[8];
                if (getFileType($perms) == "d") {
                    $isFolder = 1;
                } else {
                    $isFolder = 0;
                }
            }
            // Split up array into values (Mac)
            // skip first line
            if ($_SESSION["win_lin"] == "mac") {
                if ($count == 1) {
                    continue;
                }
                $ff = preg_split("/[\\s]+/", $ff, 9);
                $perms = $ff[0];
                $file = $ff[8];
                if (getFileType($perms) == "d") {
                    $isFolder = 1;
                } else {
                    $isFolder = 0;
                }
            }
            // Split up array into values (Win)
            if ($_SESSION["win_lin"] == "win") {
                $ff = preg_split("/[\\s]+/", $ff, 4);
                $size = $ff[2];
                $file = $ff[3];
                if ($size == "<DIR>") {
                    $isFolder = 1;
                } else {
                    $isFolder = 0;
                }
            }
            if ($file != "." && $file != "..") {
                // Check for sub folders and then perform this function
                if ($isFolder == 1) {
                    deleteFolder($file, $folder_path);
                } else {
                    // otherwise delete file
                    $file_path = $folder_path . "/" . $file;
                    if (!@ftp_delete($conn_id, "" . $file_path . "")) {
                        if (checkFirstCharTilde($file_path) == 1) {
                            if (!@ftp_delete($conn_id, "" . replaceTilde($file_path) . "")) {
                                recordFileError("file", replaceTilde($file_path), $lang_cant_delete);
                            }
                        } else {
                            recordFileError("file", $file_path, $lang_cant_delete);
                        }
                    }
                }
            }
        }
    }
    // Check if file exists
    if (checkFileExists("d", $folder, $folder_path) == 1) {
        $_SESSION["errors"][] = str_replace("[file]", "<strong>" . tidyFolderPath($folder_path, $folder) . "</strong>", $lang_folder_doesnt_exist);
    } else {
        // Chage dir up before deleting
        ftp_cdup($conn_id);
        // Delete the empty folder
        if (!@ftp_rmdir($conn_id, "" . $folder_path . "")) {
            if (checkFirstCharTilde($folder_path) == 1) {
                if (!@ftp_rmdir($conn_id, "" . replaceTilde($folder_path) . "")) {
                    recordFileError("folder", replaceTilde($folder_path), $lang_folder_cant_delete);
                    $isError = 1;
                }
            } else {
                recordFileError("folder", $folder_path, $lang_folder_cant_delete);
                $isError = 1;
            }
        }
        // Remove directory from history
        if ($isError == 0) {
            deleteFtpHistory($folder_path);
        }
    }
}
示例#14
0
/**
 * Tell if an entry is a FTP directory
 *
 * @param 		resource	$connect_id		Connection handler
 * @param 		string		$dir			Directory
 * @return		int			1=directory, 0=not a directory
 */
function ftp_isdir($connect_id, $dir)
{
    if (@ftp_chdir($connect_id, $dir)) {
        ftp_cdup($connect_id);
        return 1;
    } else {
        return 0;
    }
}
示例#15
0
 function _ftpMkDirR($sPath)
 {
     $sPwd = ftp_pwd($this->_rStream);
     $aParts = explode("/", $sPath);
     $sPathFull = '';
     if ('/' == $sPath[0]) {
         $sPathFull = '/';
         ftp_chdir($this->_rStream, '/');
     }
     foreach ($aParts as $sPart) {
         if (!$sPart) {
             continue;
         }
         $sPathFull .= $sPart;
         if ('..' == $sPart) {
             @ftp_cdup($this->_rStream);
         } elseif (!@ftp_chdir($this->_rStream, $sPart)) {
             if (!@ftp_mkdir($this->_rStream, $sPart)) {
                 ftp_chdir($this->_rStream, $sPwd);
                 return false;
             }
             @ftp_chdir($this->_rStream, $sPart);
         }
         $sPathFull .= '/';
     }
     ftp_chdir($this->_rStream, $sPwd);
     return true;
 }
示例#16
0
function fel($connid)
{
    ftp_cdup($connid);
    $p = ftp_pwd($connid);
    return $p;
}
示例#17
0
    echo "<TR><TH COLSPAN=13>";
    echo "<CENTER><B><FONT color=" . $warn_color[$sess_Data["level"]] . ">";
    echo $sess_Data["warn"];
    echo "</FONT></B></CENTER>";
    echo "<P>";
    echo "</TH></TR>";
    $sess_Data["warn"] = "";
}
// display link to the home directory
$built_data = build_row($show_col, array('', '', '', '', '', '', '', '', sprintf("~ (%s)", gettext("Home Directory"))), "D", $home_Dir);
$home = display_row($built_data, $alt_class[$alt_row % 2], "disabled");
echo "{$home}";
$alt_row = $alt_row + 1;
// display the link to the parent directory if there is one
if (ftp_pwd($fp) != "/") {
    ftp_cdup($fp);
    $NEWDIR = urlencode(ftp_pwd($fp));
    // display the .. directory
    $built_data = build_row($show_col, array('', '', '', '', '', '', '', '', sprintf(".. (%s)", gettext("Up One Directory"))), "D", "..");
    $cdup = display_row($built_data, $alt_class[$alt_row % 2], "disabled");
    echo "{$cdup}";
    $alt_row = $alt_row + 1;
}
if ($files != FALSE) {
    // this is testing for whether the ftp_rawlist starts with the dir total
    // or a directory/file, $index is the index for the files[] array
    if (count(explode(" ", $files[0])) == 2) {
        $index = 1;
    } else {
        $index = 0;
    }
示例#18
0
 /**
  * Changes to the parent directory
  * @link http://php.net/ftp_cdup
  *
  * @return boolean TRUE on success FALSE on failure
  */
 public function cdup()
 {
     return ftp_cdup($this->connection->getStream());
 }
示例#19
0
 /**
  * Change to the parent directory
  *
  * @return bool
  */
 public function levelUp()
 {
     if (is_resource($this->cid)) {
         return ftp_cdup($this->cid);
     }
 }
示例#20
0
 /**
  * ftp_cdup wrapper
  *
  * @return bool
  */
 public function cdup()
 {
     $this->checkConnected();
     return @ftp_cdup($this->_conn);
 }
示例#21
0
文件: sftp.php 项目: beyond-z/braven
 public function cdup()
 {
     return ftp_cdup($this->conn_id);
 }
示例#22
0
 /**
  * 方法:生成目录 
  * @path -- 路径 
  */
 function dir_mkdirs($path)
 {
     $path_arr = explode('/', $path);
     // 取目录数组
     $file_name = array_pop($path_arr);
     // 弹出文件名
     $path_div = count($path_arr);
     // 取层数
     foreach ($path_arr as $val) {
         if (@ftp_chdir($this->conn_id, $val) == FALSE) {
             $tmp = @ftp_mkdir($this->conn_id, $val);
             //新加FTP目录下放置文件
             if ($tmp == FALSE) {
                 echo "目录创建失败,请检查权限及路径是否正确!";
                 exit;
             }
             @ftp_chdir($this->conn_id, $val);
             $this->up_file(__FILE__ . "/../index.htm", 'index.htm');
         }
     }
     for ($i = 1; $i <= $path_div; $i++) {
         @ftp_cdup($this->conn_id);
     }
 }
示例#23
0
文件: ftp.php 项目: luozhanhong/share
 /**
  *
  * 切换目录至当前目录的父目录 (上级目录)
  *
  * @return bool
  */
 public static function cdup()
 {
     return ftp_cdup(self::$resource);
 }
示例#24
0
 /**
  * Changes to the parent directory.
  *
  * @return bool
  */
 public function moveUp()
 {
     try {
         return ftp_cdup($this->connectionId);
     } catch (\Exception $e) {
         return false;
     }
 }
示例#25
0
文件: Ftp.php 项目: xingcuntian/yaf
 /**
  * 切换到当前目录的父目录
  */
 public function cdup()
 {
     return ftp_cdup($this->link);
 }
示例#26
0
 public function update()
 {
     /*
      * Disable error reporting due to noticed thrown when directories are checked
      * It will cause constant loading icon otherwise.
      */
     error_reporting(0);
     set_time_limit(0);
     ob_start();
     $this->load->model('setting/setting');
     $this->load->language('extension/openbay');
     $data = $this->request->post;
     $data['user'] = $data['openbay_ftp_username'];
     $data['pw'] = html_entity_decode($data['openbay_ftp_pw']);
     $data['server'] = $data['openbay_ftp_server'];
     $data['rootpath'] = $data['openbay_ftp_rootpath'];
     $data['adminDir'] = $data['openbay_admin_directory'];
     $data['beta'] = isset($data['openbay_ftp_beta']) && $data['openbay_ftp_beta'] == 1 ? 1 : 0;
     if (empty($data['user'])) {
         return array('connection' => false, 'msg' => $this->language->get('error_username'));
     }
     if (empty($data['pw'])) {
         return array('connection' => false, 'msg' => $this->language->get('error_password'));
     }
     if (empty($data['server'])) {
         return array('connection' => false, 'msg' => $this->language->get('error_server'));
     }
     if (empty($data['adminDir'])) {
         return array('connection' => false, 'msg' => $this->language->get('error_admin'));
     }
     $connection = @ftp_connect($data['server']);
     $updatelog = "Connecting to server\n";
     if ($connection != false) {
         $updatelog .= "Connected\n";
         $updatelog .= "Checking login details\n";
         if (isset($data['openbay_ftp_pasv']) && $data['openbay_ftp_pasv'] == 1) {
             ftp_pasv($connection, true);
             $updatelog .= "Using pasv connection\n";
         }
         if (@ftp_login($connection, $data['user'], $data['pw'])) {
             $updatelog .= "Logged in\n";
             if (!empty($data['rootpath'])) {
                 $updatelog .= "Setting root path\n";
                 @ftp_chdir($connection, $data['rootpath']);
                 $directory_list = ftp_nlist($connection, $data['rootpath']);
             }
             $current_version = $this->config->get('openbay_version');
             $send = array('version' => $current_version, 'ocversion' => VERSION, 'beta' => $data['beta']);
             $files = $this->call('update/getList/', $send);
             $updatelog .= "Requesting file list\n";
             if ($this->lasterror == true) {
                 $updatelog .= $this->lastmsg;
                 return array('connection' => true, 'msg' => $this->lastmsg);
             } else {
                 $updatelog .= "Received list of files\n";
                 foreach ($files['asset']['file'] as $file) {
                     $dir = '';
                     $dir_level = 0;
                     if (isset($file['locations']['location']) && is_array($file['locations']['location'])) {
                         foreach ($file['locations']['location'] as $location) {
                             $updatelog .= "Current location: " . $dir . "\n";
                             // Added to allow OC security where the admin directory is renamed
                             if ($location == 'admin') {
                                 $location = $data['adminDir'];
                             }
                             $dir .= $location . '/';
                             $updatelog .= "Trying to get to: " . $dir . "\n";
                             $updatelog .= "ftp_pwd output: " . ftp_pwd($connection) . "\n";
                             if (@ftp_chdir($connection, $location)) {
                                 $dir_level++;
                             } else {
                                 if (@ftp_mkdir($connection, $location)) {
                                     $updatelog .= "Created directory: " . $dir . "\n";
                                     ftp_chdir($connection, $location);
                                     $dir_level++;
                                 } else {
                                     $updatelog .= "FAILED TO CREATE DIRECTORY: " . $dir . "\n";
                                 }
                             }
                         }
                     }
                     $filedata = base64_decode($this->call('update/getFileContent/', array('file' => implode('/', $file['locations']['location']) . '/' . $file['name'], 'beta' => $data['beta'])));
                     $tmp_file = DIR_CACHE . 'openbay.tmp';
                     $fp = fopen($tmp_file, 'w');
                     fwrite($fp, $filedata);
                     fclose($fp);
                     if (ftp_put($connection, $file['name'], $tmp_file, FTP_BINARY)) {
                         $updatelog .= "Updated file: " . $dir . $file['name'] . "\n";
                     } else {
                         $updatelog .= "FAILED TO UPDATE FILE: " . $dir . $file['name'] . "\n";
                     }
                     unlink($tmp_file);
                     while ($dir_level != 0) {
                         ftp_cdup($connection);
                         $dir_level--;
                     }
                 }
                 $openbay_settings = $this->model_setting_setting->getSetting('openbay');
                 $openbay_settings['openbay_version'] = $files['version'];
                 $this->model_setting_setting->editSetting('openbay', $openbay_settings);
                 @ftp_close($connection);
                 /**
                  * Run the patch files
                  */
                 $this->patch(false);
                 $this->load->model('extension/openbay/ebay');
                 $this->model_extension_openbay_ebay->patch();
                 $this->load->model('extension/openbay/amazon');
                 $this->model_extension_openbay_amazon->patch();
                 $this->load->model('extension/openbay/amazonus');
                 $this->model_extension_openbay_amazonus->patch();
                 $this->load->model('extension/openbay/etsy');
                 $this->model_extension_openbay_etsy->patch();
                 /**
                  * File remove operation (clean up old files)
                  */
                 $updatelog .= "\n\n\nStarting Remove\n\n\n";
                 $connection = @ftp_connect($data['server']);
                 @ftp_login($connection, $data['user'], $data['pw']);
                 if (!empty($data['rootpath'])) {
                     @ftp_chdir($connection, $data['rootpath']);
                     $directory_list = ftp_nlist($connection, $data['rootpath']);
                 }
                 $files_update = $files;
                 $files = $this->call('update/getRemoveList/', $send);
                 $updatelog .= "Remove Files: " . print_r($files, 1);
                 if (!empty($files['asset']) && is_array($files['asset'])) {
                     foreach ($files['asset'] as $file) {
                         $dir = '';
                         $dir_level = 0;
                         $error = false;
                         if (!empty($file['locations'])) {
                             foreach ($file['locations']['location'] as $location) {
                                 $dir .= $location . '/';
                                 $updatelog .= "Current location: " . $dir . "\n";
                                 // Added to allow OC security where the admin directory is renamed
                                 if ($location == 'admin') {
                                     $location = $data['adminDir'];
                                 }
                                 if (@ftp_chdir($connection, $location)) {
                                     $updatelog .= $location . "/ found\n";
                                     $dir_level++;
                                 } else {
                                     // folder does not exist, therefore, file does not exist.
                                     $updatelog .= "{$location} not found\n";
                                     $error = true;
                                     break;
                                 }
                             }
                         }
                         if (!$error) {
                             //remove the file
                             $updatelog .= "File: " . $file['name'] . "\n";
                             $updatelog .= "Size:" . ftp_size($connection, $file['name']) . "\n";
                             if (@ftp_size($connection, $file['name']) != -1) {
                                 @ftp_delete($connection, $file['name']);
                                 $updatelog .= "Removed\n";
                             } else {
                                 $updatelog .= "File not found\n";
                             }
                         }
                         while ($dir_level != 0) {
                             ftp_cdup($connection);
                             $dir_level--;
                         }
                     }
                 }
             }
             $updatelog .= "Update complete\n\n\n";
             $output = ob_get_contents();
             ob_end_clean();
             $this->writeUpdateLog($updatelog . "\n\n\nErrors:\n" . $output);
             return array('connection' => true, 'msg' => sprintf($this->language->get('text_updated'), $files_update['version']), 'version' => $files_update['version']);
         } else {
             return array('connection' => false, 'msg' => $this->language->get('error_ftp_login'));
         }
     } else {
         return array('connection' => false, 'msg' => $this->language->get('error_ftp_connect'));
     }
 }
示例#27
0
 /**
  * Tests FTP server
  *
  * @param string $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     $rand = md5(time());
     $tmp_dir = 'test_dir_' . $rand;
     $tmp_file = 'test_file_' . $rand;
     $tmp_path = W3TC_TMP_DIR . '/' . $tmp_file;
     if (!@file_put_contents($tmp_path, $rand)) {
         $error = sprintf('Unable to create file: %s.', $tmp_path);
         return false;
     }
     if (!$this->_connect($error)) {
         return false;
     }
     $this->_set_error_handler();
     if (!@ftp_mkdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to make directory: %s (%s).', $tmp_dir, $this->_get_last_error());
         @unlink($tmp_path);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (!@ftp_chdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to change directory to: %s (%s).', $tmp_dir, $this->_get_last_error());
         @unlink($tmp_path);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     if (!@ftp_put($this->_ftp, $tmp_file, $tmp_path, FTP_BINARY)) {
         $error = sprintf('Unable to upload file: %s (%s).', $tmp_path, $this->_get_last_error());
         @unlink($tmp_path);
         @ftp_cdup($this->_ftp);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     @unlink($tmp_path);
     if (!@ftp_delete($this->_ftp, $tmp_file)) {
         $error = sprintf('Unable to delete file: %s (%s).', $tmp_path, $this->_get_last_error());
         @ftp_cdup($this->_ftp);
         @ftp_rmdir($this->_ftp, $tmp_dir);
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     @ftp_cdup($this->_ftp);
     if (!@ftp_rmdir($this->_ftp, $tmp_dir)) {
         $error = sprintf('Unable to remove directory: %s (%s).', $tmp_dir, $this->_get_last_error());
         $this->_restore_error_handler();
         $this->_disconnect();
         return false;
     }
     $this->_restore_error_handler();
     $this->_disconnect();
     return true;
 }
示例#28
0
function export_ftp_php_uploaddir($dir, $oFtpConnection)
{
    global $aFtpExport;
    export_log("Uploading directory: '{$dir}' to remote location.");
    if ($dh = opendir($dir)) {
        export_log("Uploading files to remote location.");
        while (($file = readdir($dh)) !== false) {
            $filePath = $dir . "/" . $file;
            if ($file != "." && $file != ".." && !is_dir($filePath)) {
                if (!ftp_put($oFtpConnection, $file, $filePath, FTP_BINARY)) {
                    export_log("Failed to upload '{$file}'.");
                }
            }
            if ($file != "." && $file != ".." && is_dir($filePath)) {
                export_log("Create remote directory: '{$file}'.");
                ftp_mkdir($oFtpConnection, $file);
                export_log("Change remote directory to: '{$file}'.");
                ftp_chdir($oFtpConnection, $file);
                export_ftp_php_uploaddir($filePath, $oFtpConnection);
                export_log("Change remote directory: one up.");
                ftp_cdup($oFtpConnection);
            }
        }
        closedir($dh);
    }
}
示例#29
0
 // heres where most of the work takes place
 if ($action == 'cwd') {
     if ($olddir == $newdir) {
         ftp_chdir($ftp, $newdir);
     } else {
         ftp_chdir($ftp, $olddir . $newdir . '/');
         if ($oldir == '/') {
             $olddir = $newdir;
         } elseif (!($file && $newdir)) {
             $olddir = $newdir = '';
         }
         $olddir = $olddir . $newdir . '/';
     }
 } elseif ($action == 'up') {
     ftp_chdir($ftp, $connInfo['cwd']);
     ftp_cdup($ftp);
 } elseif ($action == '' && $connInfo['cwd'] != '') {
     // this must have come back from another module, try to
     // get into the old directory
     ftp_chdir($ftp, $connInfo['cwd']);
 } elseif ($olddir) {
     ftp_chdir($ftp, $olddir);
 }
 if (!$olddir) {
     $olddir = ftp_pwd($ftp);
 }
 $cwd = ftp_pwd($ftp);
 $connInfo['cwd'] = $cwd;
 // set up the upload form
 $ul_form_open = '<form name="upload" action="' . createLink($GLOBALS['target']) . '" enctype="multipart/form-data" method="post">' . "\n" . '<input type="hidden" name="olddir" value="' . $cwd . '">' . "\n" . '<input type="hidden" name="action" value="upload">' . "\n";
 $ul_select = '<input type="file" name="uploadfile" size="30">' . "\n";
示例#30
0
文件: Ftp.php 项目: bluebaytravel/ftp
 /**
  * Move up a directory.
  *
  * @return bool
  */
 public function up()
 {
     return ftp_cdup($this->connection);
 }