title: Transfer a file in PHP
body: <p>i have to transfer a created sql file from server a to server b. Currently i tried following without success:</p>
  
  <pre><code>// Some SQL executions to fill and update the tables
  ( .. )
  
  // Filename pattern
  $fileName = "dump_".date("Y-m-d-H_i_s").".sql";
  
  // Dump the tables and saves the output in dump directory 
  $dump = "mysqldump -u$USER -p$PASS $DB ".$this-&gt;dumpTables." &gt; " . $this-&gt;path."dumps/". $fileName;
  
  // Transfer the lastest sql file to the origin
  $command = "scp " . $this-&gt;path."dbbackup/" . $fileName . " user@xxx.xxx.xxx.xxx:/PATH/dumps" . $fileName;
  
  system($command, $retvalOrigin);
  if ($retvalOrigin != 0) {
          fwrite($this-&gt;logFileInstance, $this-&gt;date() . "Something went wrong! \r\n");
          fwrite($this-&gt;logFileInstance, $this-&gt;date() . "$command! \r\n");
  } 
  </code></pre>
  
  <p>Whats the problem?</p>
  
  <p>If i execute the command by hand, everything goes fine. So there is no permission problem. No unexpected log entries in my error log. If i copy the command without any vars and put this into a new php file, and call this, there is no error again.. 
  At first i thougt scp hates me, thats why i replaced the "scp" with "rsync -ave". That gives me no error, but won't copy the file to the origin server (No error log again!).</p>
  
  <p>scp -> $retvalOrigin = 1, no file on origin server, no error log</p>
  
  <p>rsync -> $retvalOrigin = 0, no file on origin server, no error log</p>
  
  <p>So what's the point? </p>
  
  <p>Edit:</p>
  
  <p>Path are ABSOLUTE, 
  SSH KEY for the executing user and www-data - no login required anymore, 
  $retVal includes ONLY 1 / 0,
  and NO in won't use for that a cron</p>