我正在尝试将文件从一台服务器移动到另一台服务器,我正在使用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;
}
答案 0 :(得分:0)
// 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);