Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将文件放在SFTP服务器上_Php_Sftp_Fopen_Wrapper - Fatal编程技术网

Php 将文件放在SFTP服务器上

Php 将文件放在SFTP服务器上,php,sftp,fopen,wrapper,Php,Sftp,Fopen,Wrapper,我想在使用公钥(而不是密码)进行身份验证后,将文件放在STFP服务器上。 命令行工作中的手动SFTP。 首先,我不能使用phpseclib。 在我的PHP.ini中'allow_url_fopen'=1 stream_get_wrappers()给了我:https,ftps,compress.zlib,compress.bzip2,php,file,glob,data,http,ftp,phar,ssh2.shell,ssh2.exec,ssh2.tunnel,ssh2.scp,ssh2.sft

我想在使用公钥(而不是密码)进行身份验证后,将文件放在STFP服务器上。 命令行工作中的手动SFTP。 首先,我不能使用phpseclib。 在我的PHP.ini中'allow_url_fopen'=1

stream_get_wrappers()给了我:https,ftps,compress.zlib,compress.bzip2,php,file,glob,data,http,ftp,phar,ssh2.shell,ssh2.exec,ssh2.tunnel,ssh2.scp,ssh2.sftp,zip

一切正常(按顺序:ssh2\u连接、ssh2\u验证\u公开密钥\u文件、ssh2\u sftp) 但是这个代码不起作用:

$sftp = ssh2_sftp($connection);
$dest = 'test.txt';
--> $sftpStream = fopen('ssh2.sftp://'.$sftp.$dest, 'w'); <---
PHP Warning:  fopen(ssh2.sftp://Resource id #32test.txt): failed to open stream: 
$sftp=ssh2\u sftp($connection);
$dest='test.txt';

-->$sftpStream=fopen('ssh2.sftp://'。$sftp.$dest,'w') phpseclib使用fsockopen,这允许url fopen不起作用。allow\u url\u fopen用于file()和file\u get\u contents()之类的内容-不用于fsockopen()。

简单错误:您忘记了
/
之间的
$resource
$dest
。因此,这将起作用:

$sftpStream = fopen('ssh2.sftp://'.$sftp.'/'.$dest, 'w');

。。如果您对文件系统的根目录具有写访问权限。您可能需要提供文件的完整路径,除了在ssh连接上执行
cwd
之外,我还没有找到一种方法在连接后将文件放入“默认”目录。

您是否与您所说的在命令行上工作的同一个用户一起执行此代码?如果您是通过Web服务器执行此页面,它将在Web服务器进程的同一用户下执行(尤其是debian/ubuntu中的www数据或rhel/centos中的httpd)