views:

1255

answers:

3

If I setup a CRON that runs a PHP script that in turn moves a file from one server to another, what would be the best way? Assume I have been given the proper username/password , and the protocol (like SFTP) is only prohibited if the language can't support it. I'm really open to options here -- these are XML files that hold order export and customer export (non-sensitive) information, and the jobs will run daily. There is the potential that one server is Linux and the other is Windows -- both are on different networks.

+2  A: 

Why not use shell_exec and scp?

<?php
    $output = shell_exec('scp file1.txt [email protected]:somedir');
    echo "<pre>$output</pre>";
?>
SoloBold
scp is a very handy and powerful tool, but may require some configuration: http://www.google.com/search?q=+password-less+SSH+login
Bob Fanger
+3  A: 

If both servers would be on Linux you could use rsync for any kind of files (php, xml, html, binary, etc). Even if one of them will be Windows there are rsync ports to Windows.

Alexandru Luchian
rsync's good too.
SoloBold
+2  A: 

Why not try using PHP's FTP functions?

Then you could do something like:

// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "Successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);
Stephen