4

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);
richsage
  • 26,912
  • 8
  • 58
  • 65
Daniel
  • 91
  • 5

3 Answers3

1

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

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
1

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

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
0

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
  • 18,104
  • 8
  • 63
  • 81
  • Ok, that I thought about too, but if possible I want to avoid that because that could cause other problems. – Daniel Jun 18 '10 at 09:25