title: Moving a file to another server via FTP using PHP
body: <p>I need to move a backup of my database file to another server automatically using cron. I have some code and it's connecting to the ftp server fine, the problem is it will not move the file. I don't know how to make it show the exact error other than "FTP upload failed!" so I don't know what the real problem is, however, I believe it's got to do with the "real" path of the file on the server and/or the real path of the directory of the other server where it's placing the file.</p>
  
  <p>Any help would be great.</p>
  
  <pre><code>$server = "MyServer"; 
  $ftp_user_name = "MyUsername";
  $ftp_user_pass = "MyPassword"; 
  $source = "bumail_data/db-backup-05-09-15__17:23.sql"; 
  $dest = 'db-backup-05-09-15__17:23.sql';
  
  $connection = ftp_connect($server);
  
  $login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
  ftp_pasv ( $connection, true );
  if (!$connection || !$login) { die('Connection attempt failed!'); }
  
  $upload = ftp_put($connection, $dest, $source, FTP_BINARY);
  
  if (!$upload) { echo 'FTP upload failed!'; }
  
  ftp_close($connection);
  </code></pre>
  
  <p>The file $source is located in httpdocs/bumail_data/FILE.sql</p>
  
  <p>The folder on the other server I want to put the file in is located before the public_html on a dir named dbbackup. So I guess that is the root dir but not sure.</p>
  
  <p>I hope that helps you understand where the files are and what I maybe need to put in the script. I have tried everything I can think of from ../dir/file to var/host/root/dir/file and so on. It just will not move the file.</p>