本文整理汇总了PHP中Ftp::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP Ftp::connect方法的具体用法?PHP Ftp::connect怎么用?PHP Ftp::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ftp
的用法示例。
在下文中一共展示了Ftp::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload()
{
if (!$this->input['video_id']) {
$this->errorOutput(NOID);
}
$sql = " SELECT video_base_path,video_path,video_filename,id FROM " . DB_PREFIX . "vodinfo WHERE id IN (" . $this->input['video_id'] . ")";
$q = $this->db->query($sql);
$video = array();
while ($r = $this->db->fetch_array($q)) {
$video[] = $r;
}
//实例化ftp,并连接
$ftp_config = array('hostname' => $this->input['hostname'], 'username' => $this->input['username'], 'password' => $this->input['password']);
$ftp = new Ftp();
if (!$ftp->connect($ftp_config)) {
$this->errorOutput('CAN NOT CONNECT FTP SERVER');
}
foreach ($video as $k => $v) {
$target_dir = date('Y', TIMENOW) . '/' . date('m', TIMENOW) . '/' . TIMENOW . hg_rand_num(6) . '/';
$target_path = $target_dir . $v['video_filename'];
$video_filepath = $v['video_base_path'] . $v['video_path'] . $v['video_filename'];
if (!$ftp->mkdir($target_dir)) {
$this->errorOutput('CAN NOT MAKE DIR');
}
if (!$ftp->upload($video_filepath, $target_path)) {
$this->errorOutput('CAN NOT UPLOAD FILE');
}
$pathinfo = pathinfo($target_path);
$filename = basename($pathinfo['basename'], '.' . $pathinfo['extension']);
$this->addItem(array('path' => $target_path, 'id' => $v['id'], 'dir' => $pathinfo['dirname'], 'filename' => $filename));
}
$this->output();
}
示例2: process
/**
* @param DatabaseBackupFile $file
* @return ResultObject[]
*/
public function process(DatabaseBackupFile $file)
{
$d = $file->getBackupDate();
$results = [];
foreach ($this->uploadsCredentials as $credentials) {
$result = new ResultObject();
// empty ResultObject means all is OK
$backupPath = $credentials['path'] . '/' . $d->format('Y') . '/' . $d->format('F');
$entireFilePath = $backupPath . '/' . $file->getFileName();
try {
$ftp = new \Ftp();
$ftp->connect($credentials['host']);
$ftp->login($credentials['username'], $credentials['password']);
if (!$ftp->fileExists($backupPath)) {
$ftp->mkDirRecursive($backupPath);
}
$ftp->put($entireFilePath, $file->getFilePath(), FTP_BINARY);
$ftp->close();
} catch (\FtpException $e) {
$this->logger->addCritical(sprintf('Uploading backup file\'s failed. %s', $e));
$result->addError('Zálohu se nepodařilo nahrát na: ' . $credentials['host'], 'error');
}
$results[] = $result;
}
return $results;
}
示例3: factory
/**
* Returns a new Ftp object. If you do not define the "file" parameter,
*
* $ftp = static::factory('group');
*
* @param string Ftp filename
* @param array array of values
* @return Ftp
*/
public static function factory($config = 'default', $connect = true)
{
$ftp = new Ftp($config);
// Unless told not to, connect automatically
$connect === true and $ftp->connect();
return $ftp;
}
示例4: update
/**
* Ist für den Abgleich der Bestellungen im Cronjob.
*/
public function update()
{
global $selectline, $oxid, $ftp;
$this->set_log('Cronjob: ' . date('d.m.Y H:i:s') . "\r\n");
try {
$ftp = new Ftp();
$ftp->connect($oxid['ftp_host']);
$ftp->login($oxid['ftp_user'], $oxid['ftp_password']);
$ftp->close();
} catch (Exception $e) {
$this->set_log('SelectConnect konnte keine Verbindung zum FTP-Server herstellen!');
exit;
}
if (!oxid_userlogin()) {
$this->set_log('SelectConnect konnte sich nicht bei Oxid einloggen!');
exit;
}
if (!$this->is_current_update_process()) {
$this->set_log("Cronjob wurde gestartet \r\n");
$this->set_lock_file();
$last_update = $this->get_last_update();
$this->set_log("Bestellungen werden in Selectline importiert \r\n");
$orders = $oxid['db']->get_results("SELECT * FROM " . $oxid['table_order'] . " WHERE OXFOLDER = '" . $oxid['get_order_status'] . "' ORDER BY OXORDERNR");
if ($orders) {
foreach ($orders as $order) {
$order_products = $oxid['db']->get_results("SELECT * FROM " . $oxid['table_orderarticles'] . " WHERE OXORDERID = '" . $order->OXID . "' ");
$order->products = $order_products;
$order_payment = $oxid['db']->get_row("SELECT * FROM " . $oxid['table_payments'] . " WHERE ('" . $order->OXPAYMENTTYPE . "' = OXID)");
$order->payment = $order_payment;
$this->set_order_to_selectline($order, true);
$oxid['db']->query("UPDATE " . $oxid['table_order'] . " SET OXFOLDER = '" . $oxid['set_order_status'] . "', OXEXPORT = 1 WHERE `OXID` = '" . $order->OXID . "' ");
}
}
$this->set_log("Bestellungstatus wird abgeglichen \r\n");
$orders = $selectline['db']->get_results("SELECT * FROM " . $selectline['table_orders'] . " WHERE [Belegtyp] = '" . $selectline['filter_order_invoice'] . "' AND [BearbeitetAm] >= CONVERT(datetime, '" . $last_update->format('d.m.Y H:i:s') . "',104)");
if ($orders) {
foreach ($orders as $order) {
$tracking_id = $this->get_tracking_id_from_selectline($order);
$updateArray = array('OXBILLNR' => $order->Belegnummer, 'OXBILLDATE' => $order->Datum->format('Y-m-d'), 'OXSENDDATE' => $order->Datum->format('Y-m-d H:i:s'), 'OXFOLDER' => $oxid['order_status_finish']);
if ($tracking_id !== NULL) {
$updateArray['OXTRACKCODE'] = $tracking_id;
}
//print_r($this->format_update_query($oxid['table_order'], $updateArray, array('OXORDERNR' => str_replace('OX', '', $order->IhrAuftrag))));
$oxid['db']->query($this->format_update_query($oxid['table_order'], $updateArray, array('OXORDERNR' => str_replace('OX', '', $order->IhrAuftrag))));
$this->set_log("Bestellung " . $order->IhrAuftrag . "/" . $order->Belegnummer . " - Status: FINISHED - Tracking: " . $tracking_id . " \r\n");
}
}
$this->set_last_update();
$this->remove_lock_file();
$this->set_log("Cron wurde beendet \r\n");
$this->set_log("\r\n##################################\r\n\r\n");
} else {
print_r('Error: Es läuft bereits Update-Prozess.');
}
}
示例5: testDownload
/**
* Download test.
* @return void
*/
public function testDownload()
{
$ftp = new Ftp();
// Opens an FTP connection to the specified host
$ftp->connect('ftp.nettephp.com');
$ftp->pasv(TRUE);
// Login with username and password
$ftp->login('nette@php7.org', 'anonymous');
// Download file 'README' to local temporary file
$temp = tmpfile();
$ftp->fget($temp, 'README', Ftp::ASCII);
// echo file
fseek($temp, 0);
$this->assertEquals("Nette Framework rocks!", stream_get_contents($temp));
}
示例6: get_ftp_content
function get_ftp_content($source, $target)
{
$result = false;
$config = array('hostname' => FTP_HOST, 'username' => FTP_USER, 'password' => FTP_PASSWORD, 'port' => FTP_PORT, 'timeout' => FTP_TIMEOUT);
$ftp = new Ftp();
$ftp->connect($config);
if ($ftp->existsFile($source)) {
$result = $ftp->download($source, $target);
} else {
access_log('log', 'No documents.');
//clear_file();
}
$ftp->close();
return $result;
}
示例7: forward_suobei
public function forward_suobei($id)
{
//获取视频id
$sql = 'SELECT content_id,vodid FROM ' . DB_PREFIX . 'materials WHERE content_id IN (' . $id . ') AND vodid !=""';
$query = $this->db->query($sql);
$k = array();
while ($row = $this->db->fetch_array($query)) {
$k[$row['content_id']] = $row['vodid'];
}
$ids = '';
$ret = array();
if (!empty($k)) {
//获取视频信息
$ids = implode(',', $k);
$keys = array_keys($k);
$vodpath = array();
//获取报料标题
$sql = 'SELECT id,title FROM ' . DB_PREFIX . 'content WHERE id IN (' . implode(',', $keys) . ')';
$query = $this->db->query($sql);
$title = array();
while ($row = $this->db->fetch_array($query)) {
$title[$row['id']] = $row['title'];
}
$title = array_combine($k, $title);
$ftp = $this->settings['App_suobei']['ftp'];
$ids = implode(',', $k);
$ret = $this->get_vodinfo($ids, $ftp['host'], $ftp['username'], $ftp['password']);
$vodpath = array();
if (!empty($ret) && is_array($ret)) {
foreach ($ret as $key => $val) {
$vodpath[$val['id']] = $ret[$key];
}
} else {
$this->errorOutput('ftp上传失败');
}
}
if (!empty($vodpath) && !empty($title)) {
//获取报料标题
//写xml文件
$this->vod_xml($vodpath, $title);
//ftp上传
//实例化ftp,并连接
$ftp_config = array('hostname' => $ftp['host'], 'username' => $ftp['username'], 'password' => $ftp['password']);
$ftp_up = new Ftp();
if (!$ftp_up->connect($ftp_config)) {
$this->errorOutput('CAN NOT CONNECT FTP SERVER');
}
foreach ($vodpath as $k => $v) {
$target_dir = $v['dir'] . '/';
$target_path = $target_dir . $v['filename'] . '.xml';
$xml_filepath = $this->settings['App_suobei']['xmldir'] . $v['filename'] . '.xml';
if (!file_exists($xml_filepath)) {
$this->errorOutput('CAN NOT FIND XML');
}
if (!$ftp_up->mkdir($target_dir)) {
$this->errorOutput('CAN NOT MAKE DIR');
}
if (!$ftp_up->upload($xml_filepath, $target_path)) {
$this->errorOutput('CAN NOT UPLOAD FILE');
}
}
$ftp_up->close();
//更新状态位
$sql = 'UPDATE ' . DB_PREFIX . 'content SET suobei=1 WHERE id IN (' . implode(',', $keys) . ')';
$this->db->query($sql);
}
return $id;
}
示例8: Ftp
<link href='css/style.css' rel='stylesheet' type='text/css'>
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/jQuery.ajaxQueue.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootstrap-select.min.js"></script>
</head>
<body class="<?php
echo $action;
?>
">
<?php
try {
$ftp = new Ftp();
$ftp->connect($oxid['ftp_host']);
$ftp->login($oxid['ftp_user'], $oxid['ftp_password']);
$ftp->close();
} catch (Exception $e) {
print_r('<p class="alert alert-danger">SelectConnect konnte keine Verbindung zum FTP-Server herstellen!</p>');
$action = 'error';
}
if (!oxid_userlogin()) {
print_r('<p class="alert alert-danger">SelectConnect konnte sich nicht bei Oxid einloggen!</p>');
$action = 'error';
}
switch ($action) {
case 'orders':
$orders = new Orders();
$items = $orders->import();
?>
示例9: _settype
$extarr = explode('.', $filename);
return end($extarr);
}
/**
* 从后缀扩展定义FTP传输模式 ascii 或 binary
*
* @access private
* @param string 后缀扩展
* @return string
*/
private function _settype($ext)
{
$text_type = array('txt', 'text', 'php', 'phps', 'php4', 'js', 'css', 'htm', 'html', 'phtml', 'shtml', 'log', 'xml');
return in_array($ext, $text_type) ? 'ascii' : 'binary';
}
/**
* 错误日志记录
*
* @access prvate
* @return boolean
*/
private function _error($msg)
{
return @file_put_contents('ftp_err.log', "date[" . date("Y-m-d H:i:s") . "]-hostname[" . $this->hostname . "]-username[" . $this->username . "]-password[" . $this->password . "]-msg[" . $msg . "]\n", FILE_APPEND);
}
}
$config = array('hostname' => 'localhost', 'username' => 'root', 'password' => 'root', 'port' => 21);
$ftp = new Ftp();
$ftp->connect($config);
$ftp->upload('1.txt', 'ftp_upload.log');
//$ftp->download('ftp_upload.log','ftp_download.log');
示例10: upload2ftp
public function upload2ftp()
{
$config = json_decode($this->input['config'], 1);
$files = json_decode($this->input['files'], 1);
include_once ROOT_PATH . 'lib/class/ftp.class.php';
$ftp = new Ftp();
$server_dir = trim($config['server_dir'], '/');
$app_dir = $config['app_dir'];
$message = array('error' => 0);
if (!$ftp->connect($config)) {
$message['error'] = 1;
$message['message'] = '连接服务器失败[' . $config['hostname'] . ']';
}
if ($server_dir && !$message['error']) {
if (!$ftp->mkdir($server_dir)) {
$message['error'] = 2;
$message['message'] = '目标目录不存在且创建失败[' . $server_dir . ']';
}
}
if (!$files && !$message['error']) {
$message['error'] = 3;
$message['message'] = '文件列表不存在[' . $files . ']';
}
if (!$message['error']) {
foreach ($files as $file) {
if (!file_exists($file)) {
//continue;
}
//返回上传错误的文件
$dfile = str_replace($app_dir, '', $file);
//如果设定了ftp目标目录
$dfile = $server_dir ? $server_dir . $dfile : $dfile;
$upload_dir = trim(str_replace('/' . basename($file), '', $dfile), '/');
if ($upload_dir) {
$ftp->mkdir($upload_dir);
}
if (!$ftp->upload($file, $dfile)) {
$message['error'] = 4;
$message['message'][$file] = $dfile;
}
}
}
//file_put_contents(CACHE_DIR . 'debug.txt', var_export($config,1));
$ftp->close();
$this->addItem($message);
$this->output();
}
示例11: Ftp
<?php
$db = Typeframe::Database();
$pm = Typeframe::Pagemill();
if ($_POST['cmd'] == 'login') {
$ftp = new Ftp();
if (!$ftp->connect(TYPEF_FTP_HOST)) {
Typeframe::Log("Failed to connect to FTP at '" . TYPEF_FTP_HOST . "'");
$pm->addLoop('errors', array('message' => "Could not connect to '" . TYPEF_FTP_HOST . "'"));
} else {
if (!$ftp->login($_POST['username'], $_POST['password'])) {
Typeframe::Log('FTP login failed');
$pm->addLoop('errors', array('message' => "Login failed."));
} else {
Typeframe::Log('FTP login succeeded');
$_SESSION['typef_ftp_user'] = $_POST['username'];
$_SESSION['typef_ftp_pass'] = $_POST['password'];
Typeframe::Redirect('FTP login confirmed.', $_POST['redirect']);
return;
}
}
$pm->setVariable('redirect', $_POST['redirect']);
}
示例12: Ftp
<?php
$db = Typeframe::Database();
$pm = Typeframe::Pagemill();
if (empty($_SESSION['typef_ftp_user']) || empty($_SESSION['typef_ftp_pass'])) {
if (defined('TYPEF_FTP_USER') && defined('TYPEF_FTP_PASS') && TYPEF_FTP_USER != '') {
// Test the provided credentials
$ftp = new Ftp();
$ftp->connect(TYPEF_FTP_HOST) or die('Invalid FTP host.');
if ($ftp->login(TYPEF_FTP_USER, TYPEF_FTP_PASS)) {
$_SESSION['typef_ftp_user'] = TYPEF_FTP_USER;
$_SESSION['typef_ftp_pass'] = TYPEF_FTP_PASS;
$ftp->close();
return;
}
}
$pm->setVariable('redirect', $_SERVER['REQUEST_URI']);
Typeframe::SetPageTemplate('/admin/ftp/login.html');
Typeframe::CurrentPage()->stop();
}
示例13: do_create
//.........这里部分代码省略.........
$data['custom_creative_width'] = 320;
$data['custom_creative_height'] = 480;
}
// End Define Image Sizes
// IF CREATIVE TYPE =1, ATTEMPT TO UPLOAD CREATIVE
if ($data['creative_type'] == 1) {
$creative_server = getconfig_var('default_creative_server');
// Generate Creative Hash
$uniqid = uniqid(time());
$creative_hash = md5($uniqid);
$file_extension = strtolower(substr(strrchr($_FILES['creative_file']['name'], "."), 1));
// Case: Remote Creative Server (FTP)
if (getconfig_var('default_creative_server') > 1) {
list($width, $height, $type, $attr) = getimagesize($_FILES['creative_file']['tmp_name']);
if ($height != $data['custom_creative_height'] or $width != $data['custom_creative_width'] or empty($file_extension)) {
global $errormessage;
$errormessage = 'The image you uploaded does not appear to be in the right dimensions. Please upload a valid image sized ' . $data['custom_creative_width'] . 'x' . $data['custom_creative_height'] . '';
global $editdata;
$editdata = $data;
return false;
}
$creative_server_detail = get_creativeserver_detail(getconfig_var('default_creative_server'));
if ($creative_server_detail['entry_id'] < 1) {
global $errormessage;
$errormessage = 'The default creative server does not seem to exist. Please change your creative server in your mAdserve control panel under Configuration>Creative Servers';
global $editdata;
$editdata = $data;
return false;
}
// Attempt: Upload
include MAD_PATH . '/modules/ftp/ftp.class.php';
try {
$ftp = new Ftp();
$ftp->connect($creative_server_detail['remote_host']);
$ftp->login($creative_server_detail[remote_user], $creative_server_detail[remote_password]);
$ftp->put($creative_server_detail[remote_directory] . $creative_hash . '.' . $file_extension, $_FILES['creative_file']['tmp_name'], FTP_BINARY);
} catch (FtpException $e) {
global $errormessage;
$errormessage = 'FTP Client was unable to upload creative to remote server. Error given: ' . $e->getMessage() . '';
global $editdata;
$editdata = $data;
return false;
}
// End: Upload
}
// End Case: Remote Creative Server (FTP)
// Case: Local Creative Server
if (getconfig_var('default_creative_server') == 1) {
include MAD_PATH . '/modules/upload/class.upload.php';
$handle = new Upload($_FILES['creative_file']);
$handle->allowed = array('image/*');
$handle->file_new_name_body = $creative_hash;
if ($handle->uploaded) {
$image_width = $handle->image_src_x;
$image_height = $handle->image_src_y;
if (!empty($image_width) && !empty($image_height) && ($image_height != $data['custom_creative_height'] or $image_width != $data['custom_creative_width'])) {
global $errormessage;
$errormessage = 'The image you uploaded does not appear to be in the right dimensions. Please upload an image sized ' . $data['custom_creative_width'] . 'x' . $data['custom_creative_height'] . '';
global $editdata;
$editdata = $data;
return false;
}
$handle->Process(MAD_PATH . MAD_CREATIVE_DIR);
if ($handle->processed) {
// OK
} else {
示例14: file_remote_upload
function file_remote_upload($filename)
{
global $_W;
if (empty($_W['setting']['remote']['type'])) {
return false;
}
if ($_W['setting']['remote']['type'] == '1') {
require IA_ROOT . '/framework/library/ftp/ftp.php';
$remoteConfig = array('hostname' => $_W['setting']['remote']['ftp']['host'], 'username' => $_W['setting']['remote']['ftp']['username'], 'password' => $_W['setting']['remote']['ftp']['password'], 'port' => $_W['setting']['remote']['ftp']['port'], 'ssl' => $_W['setting']['remote']['ftp']['ssl'], 'passive' => $_W['setting']['remote']['ftp']['pasv'], 'timeout' => $_W['setting']['remote']['ftp']['timeout']);
$ftp = new Ftp($remoteConfig);
if (true === $ftp->connect()) {
$pathinfo = pathinfo($filename);
$dirs = explode('/', $_W['setting']['remote']['ftp']['dir'] . '/' . $pathinfo['dirname']);
$dir = '';
foreach ($dirs as $row) {
if (!empty($row)) {
$dir .= '/' . $row;
$ftp->mkdir($dir);
}
}
$desfile = $_W['setting']['remote']['ftp']['dir'] . '/' . $filename;
if ($ftp->upload(ATTACHMENT_ROOT . '/' . $filename, $desfile)) {
return true;
} else {
return error(1, '远程附件上传失败,请检查配置并重新上传');
}
} else {
return error(1, '远程附件上传失败,请检查配置并重新上传');
}
} elseif ($_W['setting']['remote']['type'] == '2') {
require IA_ROOT . '/framework/library/alioss/sdk.class.php';
$oss = new ALIOSS($_W['setting']['remote']['alioss']['key'], $_W['setting']['remote']['alioss']['secret'], $_W['setting']['remote']['alioss']['url'] . '.aliyuncs.com');
$options = array(ALIOSS::OSS_FILE_UPLOAD => ATTACHMENT_ROOT . '/' . $filename, ALIOSS::OSS_PART_SIZE => 5242880);
$response = $oss->create_mpu_object($_W['setting']['remote']['alioss']['bucket'], $filename, $options);
if ($response->status == 200) {
return true;
} else {
return error(1, '远程附件上传失败,请检查配置并重新上传');
}
}
}
示例15: ftpUpload
/**
* 通过FTP上传图片
* FTP上传不检查文件是否已存在(存在会返回FALSE)
* @param string $uploadformname 需要上传的表单名,$_FILES中
* @return boolean
*/
public function ftpUpload($uploadformname)
{
if (empty($this->_ftpconf)) {
self::$message = '未设置FTP登录信息';
return false;
}
//文件检查
if (!$this->check($uploadformname)) {
return false;
}
//要上传的图片缓存信息
$upfile = $_FILES[$uploadformname];
//图像类型
$imgtype = exif_imagetype($upfile['tmp_name']);
//图片尺寸信息
$size = getimagesize($upfile['tmp_name']);
$ftp = new Ftp();
$constatus = $ftp->connect($this->_ftpconf);
if (!$constatus) {
self::$message = '上传服务器连接失败';
return false;
}
//尝试创建目录,不返回状态,有可能目录已存在
$ftp->mkdir($this->_dir);
$upsatus = $ftp->upload($upfile['tmp_name'], $this->_dir . $this->_savename, '');
if (!$upsatus) {
self::$message = '上传失败,服务器繁忙';
return false;
}
//返回图片属性
self::$picinfo = pathinfo($this->_dir . $this->_savename);
self::$picinfo['width'] = $size[0];
self::$picinfo['height'] = $size[1];
self::$picinfo['size'] = $upfile['size'];
self::$message = '成功';
return true;
}