public function authorize() { global $_G, $_GET, $clouds; if (empty($_G['uid'])) { dsetcookie('_refer', rawurlencode(BASESCRIPT . '?mod=connect&op=oauth&bz=ftp')); showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1)); } if (submitcheck('ftpsubmit')) { $config = $_GET['config']; $config['password'] = authcode($config['password'], 'ENCODE', md5(getglobal('config/security/authkey'))); $config['bz'] = 'ftp'; $uid = defined('IN_ADMIN') ? 0 : $_G['uid']; $config['on'] = 1; $ftp = new dzz_ftp($config); if ($ftp->error()) { showmessage('FTP 参数设置错误,请检查', dreferer()); } if ($ftp->connect()) { $config['uid'] = $uid; if ($id = DB::result_first("select id from %t where uid=%d and host=%s and port=%d and username=%s", array(self::T, $uid, $config['host'], $config['port'], $config['username']))) { DB::update(self::T, $config, "id ='{$id}'"); } else { $config['dateline'] = TIMESTAMP; $id = DB::insert(self::T, $config, 1); } if (defined('IN_ADMIN')) { $setarr = array('name' => $config['cloudname'], 'bz' => 'ftp', 'isdefault' => 0, 'dname' => self::T, 'did' => $id, 'dateline' => TIMESTAMP); if (!DB::result_first("select COUNT(*) from %t where did=%d and dname=%s ", array('local_storage', $id, self::T))) { C::t('local_storage')->insert($setarr); } showmessage('do_success', BASESCRIPT . '?mod=cloud&op=space'); } else { showmessage('do_success', BASESCRIPT . '?mod=connect'); } } else { showmessage('尝试连接ftp未成功,请检查参数后重试', dreferer()); } } else { include template('oauth_ftp'); } }
public function copy_file($srcfile, $desfile, $type) { global $_G; if (!is_file($srcfile)) { return false; } if ($type == 'file') { $this->mkdirs(dirname($desfile)); copy($srcfile, $desfile); } elseif ($type == 'ftp') { $siteftp = $_GET['siteftp']; $siteftp['on'] = 1; $siteftp['password'] = authcode($siteftp['password'], 'ENCODE', md5($_G['config']['security']['authkey'])); $ftp =& dzz_ftp::instance($siteftp); $ftp->connect(); $ftp->upload($srcfile, $desfile); if ($ftp->error()) { return false; } } return true; }
function ftp_list($path, $iconv = 1) { $path = dzz_ftp::clear($path); if (empty($path)) { $path = self::ftp_pwd(); } $files = array(); $rawList = ftp_rawlist($this->connectid, $path); $data = self::parseRawList($rawList); //print_r($rawList);exit('dfdf'); foreach ($data as $key => $value) { $value['path'] = $iconv ? diconv(preg_replace("/\\/+/", '/', $path . '/' . $value['name']), $this->config['charset'], CHARSET) : preg_replace("/\\/+/", '/', $path . '/' . $value['name']); $value['name'] = $iconv ? diconv($value['name'], $this->config['charset'], CHARSET) : $value['name']; $data[$key] = $value; } return $data; }