$config = array(
'host' =>'211.*.*.*', //服务器
'port' => '23', //端口
'username' =>'test', //用户名
'password' =>'*****', //密码
);
$ftp = new Sftp($config);
$localpath="E:/www/new_20170724.csv";
$serverpath='/new_20170724.csv';
$st = $ftp->upftp($localpath,$serverpath); //上传指定文件
if($st == true){
echo "success";
}else{
echo "fail";
}
<?php
/**
* SFtp上传下载文件
*
*/
namespace Common\ORG\Util;
class Sftp
{
// 初始配置为NULL
private $config = NULL;
// 连接为NULL
private $conn = NULL;
// 初始化
public function __construct($config)
{
$this->config = $config;
$this->connect();
}
public function connect()
{
$this->conn = ssh2_connect($this->config['host'], $this->config['port']);
if( ssh2_auth_password($this->conn, $this->config['username'], $this->config['password']))
{
}else{
echo "无法在服务器进行身份验证";
}
}
// 传输数据 传输层协议,获得数据
public function downftp($remote, $local)
{
$ressftp = ssh2_sftp($this->conn);
return copy("ssh2.sftp://{$ressftp}".$remote, $local);
}
// 传输数据 传输层协议,写入ftp服务器数据
public function upftp( $local,$remote, $file_mode = 0777)
{
$ressftp = ssh2_sftp($this->conn);
return copy($local,"ssh2.sftp://{$ressftp}".$remote);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有