I'm trying to write a file from one hosting account to another (same server) with the following code (credentials redacted):
$fn = 'foo.bar';
$ftp_user = 'user@mydomain.com';
$ftp_pass = 'my-pass';
$ftp_host = 'ip.xx.xx.xx';
$ftp_uri = 'ftp://'.$ftp_user.':'.$ftp_pass.'@'.$ftp_host.'/home/user/public_html/test_dir/'.$fn;
$content = 'asdq3ersesdf';
$options = array('ftp' => array('overwrite' => true));
$stream = stream_context_create($options);
file_put_contents($ftp_uri, $content, 0, $stream);
But I get:
failed to open stream: FTP server reports 550 Can't check for file existence in...
I've verified the account credentials are correct.
This answer talks about the need in PHP to specify the full path to the dir, including account username. The path above is correct, i.e. /home/user/public_html/test_dir
.
This answer says something about having to set file size, but that question is about reading, not writing.
What am I doing wrong?
[[UPDATE]]
Interestingly, everything works fine if I use PHP's dedicated FTP funcs e.g. ftp_put()
, just not via the protocol.