开发者

PHP5, use SSH2 functions to DL all files in a folder then delete them from remote server

开发者 https://www.devze.com 2023-03-19 11:28 出处:网络
I\'m trying to DL a file f开发者_StackOverflow中文版rom one server to another. $ftpHandle = ssh2_connect(\'ftp.remoteServer.net\', 22)

I'm trying to DL a file f开发者_StackOverflow中文版rom 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.


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:

$sftp = ssh2_sftp($ftpHandle);
$handledir = opendir("ssh2.sftp://$sftp$dir");
0

精彩评论

暂无评论...
验证码 换一张
取 消