dongpo2458 2018-06-11 18:27
浏览 63
已采纳

如何在php中使用fopen打开ftps路径; 没有收到来自的识别字符串

I'm trying to push string data to a remote ftp path. I've done this before in other settings, but in this case the server doesn't seem to recognize the identification string. This is probably just a small syntax error on the ftp path string, but I can't see it.

I know that I'm reaching the remote server because I can check the log file and see the message

Did not receive identification string from xxx.xxx.xxx.xxx

for each attempt that I make.

After hanging for a while my script simply returns the error

Warning: fopen() failed to open stream.

My file path is formatted thusly:

$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

The part of the script that deals with the connection is as follows:

$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.');
}
  • 写回答

1条回答 默认 最新

  • dongyongju9560 2018-06-13 20:55
    关注

    This error may indicate you are attempting to access an SFTP/SSH server through the FTP wrapper. FTP/FTPS and SSH/SFTP are not compatible protocols so don't confuse FTPS with SFTP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了