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

bf1o4zei  于 2023-01-12  发布在  PHP
关注(0)|答案(2)|浏览(126)

我有两个相似的网站。一些内容是相同的两个网站。我有一些文件在特定的文件夹中的一个网站说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);

?>

我得到连接的消息,但显示“有一个问题”。请任何人都可以尝试这个。
问候你,瑞卡

x759pob2

x759pob21#

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";

}
w6mmgewl

w6mmgewl2#

$connection = ssh2_connect('IP address', Port_No);
ssh2_auth_password($connection, 'server_username', 'server_password');
ssh2_scp_send($connection,'File_Path','Destination_Path', 0644);

相关问题