繁体   English   中英

如何将文件从一台服务器移到另一台?

[英]How to move file from one server to another?

我正在使用FTP功能将文件从一台服务器移动到另一台服务器。 我尝试如下:

$path = $file['file'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
if($ext == 'pdf') {
  $pdf->Output($usrname.'TripHub.pdf','F');
  $file = '/mnt/target06/844844/847596/dev.server.com/web/content/'.$usrname.'TripHub.pdf';
  $fp = fopen($file, 'r');
  $ftp_server = "ftp.server.com";  //address of ftp server (leave out ftp://)
  $ftp_user_name = "xxxxx"; // Username
  $ftp_user_pass = "xxxxx";   // Password
  $conn_id = ftp_connect($ftp_server);        // set up basic connection
  // login with username and password, or give invalid user message
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h1>You do not have access to this ftp server!</h1>");
  // try to upload $file
   ftp_chdir($conn_id, "hub.server.com/web/content/wp-content/uploads/edd/".date("Y")."/".date("m"));
   //echo "Current directory: " . ftp_pwd($conn_id) . "\n";
  if (ftp_fput($conn_id, $file, $fp, FTP_ASCII) ) {
    echo "Successfully uploaded $file\n";
  } else {
    echo "There was a problem while uploading $file\n";
  }
  exit;
}
// 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM