我有目录/ mnt / Folder /
里面有文件夹,例如:
2019-08-13
2019-08-12
2019-08-11
2019-08-10
每个文件夹还包含一些文件
我需要将所有这些数据复制到SFTP服务器,但现在我只能复制文件,不能复制文件夹。我必须使用哪个功能来复制文件夹,而不仅仅是文件
$connection = ssh2_connect($host, $port);
ssh2_auth_password($connection, $user, $pass);
$sftp = ssh2_sftp($connection);
$handle2 = opendir("/mnt/Folder");
while (false != ($entry2 = readdir($handle2))){
if($entry2 != '.' && $entry2 != '..' && $entry2 != '.DS_Store') {
$localFile="/mnt/Folder/$entry2";
$remoteFile="/Folder/$entry2";
$stream = fopen("ssh2.sftp://$sftp$remoteFile", 'w');
$file = file_get_contents($localFile);
fwrite($stream, $file);
unlink("/mnt/Folder/$entry2");
}
}
fclose($stream);