tags:

views:

66

answers:

3

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);
+1  A: 

You need a PHP with OpenSSL support compiled in. Then, use ftps:// instead of ftp://. More info on FTPS.

Sjoerd
The OpenSSL-support is enabled and I allready tried with ftps, but obviously the server is an sftp. Does that matter?
Daniel
Yes. SFTP is something quite different than FTPS.
Sjoerd
A: 

An easier solution would be to save the file in a temporary directory, then execute a shell command to actually send off the file.

Jamie Wong
Ok, that I thought about too, but if possible I want to avoid that because that could cause other problems.
Daniel
A: 

Use ssh2.sftp:// instead of ftp://. See ssh2_sftp.

Sjoerd
Ok, that's seems to be the right way, but it becomes a little more complex.
Daniel