PHP中的ssh2://可以使用哪些文件操作 [英] What file operations are available with ssh2:// in PHP

查看:367
本文介绍了PHP中的ssh2://可以使用哪些文件操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重写一种功能,该功能可以处理和排序本地服务器上的文件,而该功能可以在通过ssh连接到达的远程服务器上进行处理.

I'm rewriting a function that processed and sorted files on the local server with one that can do so on a remote server reached through an ssh connection.

现有系统使用pecl ssh2库来抓取特定文件,例如:

The existing system uses the pecl ssh2 library to grab specific files such like:

if ($stream = @fopen("ssh2.sftp://$sftp/$filename", "r")) {
//do stuff...
}

但是我还不知道文件名.我不得不使用

But I don't know the filename already. I hade this working locally using

$file_path =  ABSOLUTE_PATH . UPLOAD_URL . $importfolder . '/';
$file = '*.xml';
$files = glob($file_path.$file);

我无法通过ssh服务器运行glob()

I can't get glob() working through the ssh server

$files = glob("ssh2.sftp://$sftp/*.xml");

(尽管目录中有许多xml文件(sftp连接到单个目录),但总是空白.

(always comes back blank despite a number of xml files in the directory (the sftp connection is to a single directory).

我该如何实现?我可以在这里使用glob()之类的功能吗?

how can I acheive this? Can I use functions like glob() here?

推荐答案

,您可以简单地使用 ssh2函数. ..

you could simply use the ssh2 functions...

即.

$session = ssh2_connect('some.server', 22);
ssh2_auth_password($session, 'username', 'password');
$stream = ssh2_exec($session, 'ls -la /some/path');
stream_set_blocking($stream, true);
echo "list of files: " . stream_get_contents($stream);

这篇关于PHP中的ssh2://可以使用哪些文件操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆