0

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\n";
    }
    else 
    {
        echo "There was a problem\n";
    }

    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!");
}
Amit Gaud
  • 756
  • 6
  • 15
Johny
  • 1
  • 1

1 Answers1

0

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

Amit Gaud
  • 756
  • 6
  • 15
  • Thanks Amit for your response! Unfortunately, the tutorial is not what I need. It checks if the connection was successful before the script log in to the FTP server to avoid errors like this "Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/content/98/10339998/html/upload.php on line 65 FTP connection has encountered an error!Attempted to connect to thelegendmaker.net.." – Johny May 23 '17 at 07:00