PHP5,使用SSH2函数DL删除文件夹中的所有文件,然后从远程服务器删除它们
我正在尝试将文件从一台服务器DL 到另一台服务器。
$ftpHandle = ssh2_connect('ftp.remoteServer.net', 22)
ssh2_auth_password($ftpHandle, $userName, $password)
成功连接和登录后,我运行以下命令:
$dir = "/dl";
$handledir = opendir($dir);
但是当然,这失败了......我不知道为什么。它说该文件夹不存在。 /dl 是远程服务器上的绝对路径。
我有一种感觉,“opendir”正在查找我的本地服务器(正在运行的服务器),而不是远程服务器。
这里的目标是查看此文件夹并 DL 文件夹中的每个文件。下载后,可以将其从远程服务器上删除。
I'm trying to DL a file from one server to another.
$ftpHandle = ssh2_connect('ftp.remoteServer.net', 22)
ssh2_auth_password($ftpHandle, $userName, $password)
After a successful connection and login, I run this:
$dir = "/dl";
$handledir = opendir($dir);
But of course, this fails...and I don't know why. It says the folder doesn't exist. /dl is the absolute path on the remote server.
I have a feeling that "opendir" is looking on my local server (where this is being run), and not the remote one.
The goal here is to look in this folder and DL every file in the folder. After it downloads, it can delete it off of the remote server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重新阅读你的问题后,我认为问题是,你没有告诉 opendir() 它应该在 SSH2 连接上运行。默认情况下,它是本地文件系统,但您希望它在 SSH 连接上运行。
要在 SSH 连接上进行操作,初始化 SSH SFTP 子系统PHP 手册 首先,然后通过 SSH2 SFTP 文件系统包装器访问资源:
After re-reading your question, I think the problem is, that you don't tell opendir() that it should operate on the SSH2 connection. By default, it's the local filesystem, but you want it to operate on your SSH connection.
To operate on the SSH connection, initialize the SSH SFTP subsystem PHP Manual first and then access resources via the SSH2 SFTP filesystem wrapper: