Hey. I'm trying to make a code which would write (or rewrite) a file on a remote server, using ftp. Here is my code so far:
$user = 'myusername';
$pass = 'mypassword';
$file = 'hey.htm';
if ($ftp = fsockopen ("users.pandora.be", 21));
fputs($ftp,"USER $user\r\n");
fputs($ftp,"PASS $pass\r\n");
fputs($ftp,"DELE $file\r\n");
fputs($ftp,"QUIT\r\n");
fclose($ftp);
$handle = fopen ('ftp://' . $user . ':' . $pass . '@users.pandora.be/' . $file, 'w');
fwrite ($handle, 'hello!');
fclose ($handle);
This works fine, but the problem here is that I connect twice, which is a waste of time. Would it be possible to do all this using only one connection? I think it should be possible to write the file using the socket, but I don't know how.
Thanks!