I have a PHP program which reads out and writes to a file which is on an FTP server, the first time writing goes fine, but when I try to write a second time I got 2 different errors:
Warning: file_put_contents(ftp://...@Directory/map/Sources/data.txt): failed to open stream: FTP server reports 550 End in C:\Apache24\htdocs\Directory\Sources\form.php on line 42
and the second:
Warning: file_put_contents(ftp://...@Directory/map/Sources/data.txt): failed to open stream: Failed to set up data channel: No connection could be made because the target machine actively refused it. in C:\Apache24\htdocs\Directory\Sources\form.php on line 42
And then it just repeats the second error.
I haven't tried anything yet, because I don't know where to start.
session_start();
$path = 'ftp://username:password@Directory/map/Sources/data.txt'; //FTP
//$path = 'C:\xampp\htdocs\NPS\Sources\data.txt'; //local path
$stream_options = array('ftp' => array('overwrite' => true));
$stream_context = stream_context_create($stream_options);
$text_file = fopen($path,'r'); //open file
$text_data = file_get_contents($path, filesize($path)); //read out file
//write old data along with new data
file_put_contents($path, $text_data . "text", 0, $stream_context);
//session stop
session_destroy();
I expect the code to write the data which I fill in beforehand with a form which I send, however it writes only once and then it just shows the errors.