【问题标题】:copy files from one server to another using php使用php将文件从一台服务器复制到另一台服务器
【发布时间】:2014-05-17 19:15:27
【问题描述】:

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


?>

我收到连接消息,但显示“出现问题”。请任何人都可以试试这个..

问候, 雷卡

【问题讨论】:

  • This 可能会有所帮助
  • 我无法理解你的回答。
  • 我认为服务器路径有问题。谁能告诉我服务器路径是否正确
  • 为什么不试试 rsync 来完成这个任务,除非你真的需要在 php.ini 中这样做。 FTP 以明文方式传递密码,除非您在本地传输,否则您真的不想使用它。

标签: php file ftp transfer


【解决方案1】:
$connection = ssh2_connect('IP address', Port_No);
ssh2_auth_password($connection, 'server_username', 'server_password');
ssh2_scp_send($connection,'File_Path','Destination_Path', 0644);

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2021-06-22
      • 1970-01-01
      • 2016-02-26
      • 2018-07-08
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 2011-02-05
      • 2011-02-06
      相关资源
      最近更新 更多