简体   繁体   English

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

[英]copy files from one server to another using php

I have two similar websites.Some of the content are same in both sites.I have some files in specific folder in one website say AI want to copy some specific files from Website A to website B.我有两个相似的网站。两个网站的某些内容相同。我在一个网站的特定文件夹中有一些文件,说 AI 想将一些特定文件从网站 A 复制到网站 B。

I have tried ftp functions in php but not working.我在 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);


?>

I get connected message but display "There was a problem".Pls can anyone try this..我收到已连接的消息,但显示“出现问题”。请任何人都可以试试这个..

Regards, Rekha问候, 雷哈

change last part where ftp_get to ftp_putftp_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";

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

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

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