使用 php 将文件从一台服务器复制到另一台服务器

问题描述 投票:0回答:2

我有两个相似的网站。两个网站的某些内容是相同的。我在一个网站的特定文件夹中有一些文件,比如 A。我想将一些特定文件从网站 A 复制到网站 B。

我尝试过 php 中的 ftp 功能,但不起作用。

 <?php

// define some variable

$local_file = 'eg.html';

$server_file = 'http://example.com/horoscope/M12459TAM_03092009_123239.html';

// set up basic connection

$conn_id = ftp_connect("example.com");


// login with username and password

$login_result = ftp_login($conn_id, 'username', 'password');

echo is_array(ftp_nlist($conn_id, ".")) ? 'Connected!' : 'not Connected! :(';

ftp_pasv($conn_id, true);

// try to download $server_file and save to $local_file

if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {

    echo "Successfully written to $local_file\n";

} else {

    echo "There was a problem\n";

}
// close the connection

ftp_close($conn_id);


?>

我收到连接消息,但显示“有问题”。请任何人尝试这个..

问候, 雷卡

php file ftp transfer
2个回答
0
投票

将最后一部分

ftp_get
更改为
ftp_put

if (ftp_put($conn_id, $local_file, $server_file, FTP_BINARY)) {

    echo "Successfully written to $local_file\n";

} else {

    echo "There was a problem\n";

}

0
投票
$connection = ssh2_connect('IP address', Port_No);
ssh2_auth_password($connection, 'server_username', 'server_password');
ssh2_scp_send($connection,'File_Path','Destination_Path', 0644);
© www.soinside.com 2019 - 2024. All rights reserved.