我正在尝试将字符串数据推送到远程ftp路径。我以前在其他设置中这样做过,但在这种情况下,服务器似乎无法识别标识字符串。这可能只是ftp路径字符串上的一个小语法错误,但我看不到它。
我知道我正在到达远程服务器,因为我可以检查日志文件并看到消息
Did not receive identification string from xxx.xxx.xxx.xxx
对于我的每一次尝试。
挂起一段时间后,我的脚本简单地返回错误
Warning: fopen() failed to open stream.
我的文件路径格式如下:
$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
处理连接的脚本部分如下所示:
$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.');
}
https://stackoverflow.com/questions/50803943
复制相似问题