Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php将文件从一台服务器复制到另一台服务器_Php_File_Ftp_Transfer - Fatal编程技术网

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

使用php将文件从一台服务器复制到另一台服务器,php,file,ftp,transfer,Php,File,Ftp,Transfer,我有两个相似的网站。两个网站中的一些内容是相同的。我在一个网站的特定文件夹中有一些文件,比如说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 con

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


?>

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

问候,,
Rekha

ftp\u get
的最后一部分更改为
ftp\u 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";

}

可能会有帮助我无法理解你的答案。我认为服务器路径有问题。有人能告诉我服务器路径是否正确吗?为什么不尝试rsync来完成此任务,除非你真的需要在php中执行此操作。FTP以明文形式传递密码,除非您在本地传输,否则您确实不想使用该密码。
$connection = ssh2_connect('IP address', Port_No);
ssh2_auth_password($connection, 'server_username', 'server_password');
ssh2_scp_send($connection,'File_Path','Destination_Path', 0644);