duanpan7011 2017-05-22 14:43
浏览 29

too long

Can you please assist me. I am trying to copy a file to the folder inside the application. The script is working on my local machine however when I run it on Cpanel server it shows an error "ftp_login() expects parameter 1 to be resource, Boolean given"

Here is the script which I tested

    $folder_path = "192.xx.xx.xx\TMS"; 
    $local_file = "CurrentFile\Inbound.xls";
    $server_file = "CurrentFile\Inbound.xls";
    //-- Connection Settings
    $ftp_server = "192.xx.xx.xx"; // Address of FTP server.
    $ftp_user_name = "FTP server username"; // Username
    $ftp_user_pass = "FTP server Password"; // Password

    $target = 'CurrentFile';
    if (!file_exists($target)) 
    {
            die("Target directory doesn't exist.");
    }
    else if (!is_writable($target)) 
     {
            die("Insufficient privileges to write to the target directory!");
    }
    // set up basic connection
    $conn_id = ftp_connect($ftp_server);
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    // 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
";
    }
    else 
    {
        echo "There was a problem
";
    }

    function fileExists($path)
    {
        return (@fopen($path,"r")==true);
    }
    ftp_close($conn_id);

I think the script is failing to connect to the FTP server. If I add this just after I create the connection It returns "connection Failed".

 if(!$conn_id) {
die("Connection failed!");
}
  • 写回答

1条回答 默认 最新

  • dousong3760 2017-05-22 15:07
    关注

    I am not used this but I have suggested go to this tutorial ftp_login expects parameter 1 to be a resource and let me know what happen to this

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?