搞這個SFTP檔案傳輸搞了一整天真是醉了,從sftp安裝,到php的ssh2擴充安裝,最後到php應用ssh2來上傳檔案;最後就沒有最後了
Failure creating remote file: (null) 一直報這個錯誤!網上能搜的基本找了個遍都不起作用,一開始以為laravel架構問題,後來寫成原生php腳本也是這個錯誤,Fine!很好真的沒轍了;
解決方法:
使用
use League\Flysystem\Sftp\SftpAdapter;
use League\Flysystem\Filesystem;
$adapter = new SftpAdapter([
‘host‘ => ‘example.com‘,
‘port‘ => 22,
‘username‘ => ‘username‘,
‘password‘ => ‘password‘,
‘privateKey‘ => ‘path/to/or/contents/of/privatekey‘,
‘root‘ => ‘/path/to/root‘,
‘timeout‘ => 10,
‘directoryPerm‘ => 0755
]);
$filesystem = new Filesystem($adapter);
//擷取到對象之後
1. $filesystem->put(‘遠端檔案路徑‘,‘内容‘);
2. $filesystem->putstream(‘遠端檔案路徑‘,‘檔案句柄‘);//通過fopen擷取句柄
個人備忘:
linux/ubuntu系統中安裝了ssh會自帶sftp,如果沒有配置的話會一直連接配接不上遠端
Unable to negotiate with 113.105.66.197 port 8521: no matching host key type found. Their offer: ssh-dss
Couldn‘t read packet: Connection reset by peer
解決方法:
在/個人目錄/.ssh/下面 添加config檔案
vi /個人目錄/.ssh/config
HostkeyAlgorithms +ssh-dss 添加這段話儲存退出,在連接配接一下SFTP試試
原文:http://www.cnblogs.com/cyq632694540/p/7117556.html