首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在php中使用fopen打开ftps路径;未收到来自的标识字符串

如何在php中使用fopen打开ftps路径;未收到来自的标识字符串
EN

Stack Overflow用户
提问于 2018-06-12 02:27:33
回答 1查看 337关注 0票数 0

我正在尝试将字符串数据推送到远程ftp路径。我以前在其他设置中这样做过,但在这种情况下,服务器似乎无法识别标识字符串。这可能只是ftp路径字符串上的一个小语法错误,但我看不到它。

我知道我正在到达远程服务器,因为我可以检查日志文件并看到消息

代码语言:javascript
复制
Did not receive identification string from xxx.xxx.xxx.xxx

对于我的每一次尝试。

挂起一段时间后,我的脚本简单地返回错误

代码语言:javascript
复制
Warning: fopen() failed to open stream.

我的文件路径格式如下:

代码语言:javascript
复制
$ftp_path = "ftps://user:password@remoteaddress:12345/path/to/file/filename.txt";//port 12345 is deliberate because I use port forwarding on the server to reduce failed hack attempts

处理连接的脚本部分如下所示:

代码语言:javascript
复制
$ftp_path = "ftps://user:password@remoteaddress:12345/path/to/file/filename.txt";
// Allow/disallow overwriting of existing files on the remote FTP server
$stream_options = array('ftps' => array('overwrite' => false));
// Creates a stream context resource with the defined options
$stream_context = stream_context_create($stream_options);
// Opens the file for writing and truncates it to zero length 
if ($fh = fopen($ftp_path, 'w', 0, $stream_context)){
    // Writes contents to the file
    if(fputs($fh, $content)){
        echo "records pushed successfully.";
    } else {
        echo "The stream was opened, but the records failed to push.";
    }
    // Closes the file handle
    fclose($fh);
} else {
    die('Could not open remote ftp.');
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-14 04:55:47

此错误可能表示您正试图通过FTP包装程序访问SFTP/SSH服务器。FTP/FTPS和SSH/SFTP是不兼容的协议,所以不要混淆FTPS和SFTP。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50803943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档