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.

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?