How can I write a file on an sftp-server with PHP?
Posted
by Daniel
on Stack Overflow
See other posts from Stack Overflow
or by Daniel
Published on 2010-06-18T08:59:08Z
Indexed on
2010/06/18
9:43 UTC
Read the original article
Hit count: 217
Hi, I hope someone here could help me, because I couldn't find any solution with Google. What I have to do is to generate a XML-string (that works) an save that directly into a file on an sftp-server.
So far, so good... I used the following code with ftp and it works to, but not with ftps. So I either need another options-configuration for the stream or a different way to solve that task.
Here my current code:
$host = 'ftp.example.com';
$port = 22;
$user = 'xxxxxx';
$pass = 'xxxxxx';
$file = 'test_' . time() . '.txt';
$ftpPath = sprintf('ftp://%s:%s@%s:%d/%s', $user, $pass, $host, $port, $file);
$context = stream_context_create(array('ftp' => array('overwrite' => true)));
file_put_contents($ftpPath, 'test', 0, $context);
© Stack Overflow or respective owner