我尝试在两个foreach
循环中创建目录并从一些本地文件夹中上传递归文件。
所有似乎都没问题ssh2_connect()
和ssh2_auth_password()
返回true。
还可以创建文件夹。文件夹是在远程创建的。
但在那之后,当我尝试将文件从该文件夹上传到远程时,我收到了这个错误:
ssh2_scp_send(): supplied resource is not a valid SSH2 Session resource
以下是我的例子:
<?php
$sshRes = ssh2_connect('my_hostname.com', 22);
//both return true here
ssh2_auth_password($sshRes, $user_ssh, $pass_ssh);
$sftp = ssh2_sftp($sshRes);
$local_folders = glob($my_local_path."/*",GLOB_ONLYDIR);
$remote_base = "/remote_base";
foreach($local_folders as $local_folder){
$folder_name = basename($local_folder);
$remote_path = $remote_base."/".$folder_name;
if(!is_dir("ssh2.sftp://$sftp/$remote_path")){
if(ssh2_sftp_mkdir($sftp, $remote_path, 0755)){
echo "$remote_path created ok"
}else{
echo "$remote_path creation failed";
}
}
$files = glob($local_folder."/*");
foreach($files as $local_file){
$file_name = basename($local_file);
//!!! here I got the error.!!!
if(ssh2_scp_send($sftp, $local_file, $remote_path."/".$file_name, 0644)){
echo "$file_name UPLOAD OK";
}else{
echo "$file_name UPLOAD FAIL";
}
}
}
?>
有人可以告诉我出了什么问题吗?