Reputation: 2337
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.');
}
Upvotes: 0
Views: 601
Reputation: 35357
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.
Upvotes: 1