PHP - ftp_put(): File does not exist - but it does

2019-06-14 14:56发布

I try to upload a file with ftp_put(), it does not seem to find the path while it's there, it's ran on the CLI and will be scheduled in a cron

[root@***** v1]# php cron_daily.php
[PREPROD][INFO] Creating file '/somepath/uploads/billingExport.pdf'
[PREPROD][WARNING] ftp_put(): File does not exist.  err:2 '/somepath/cron_billing.php' [141]
Could not upload file '/somepath/uploads/billingExport.pdf'

the file is there and should be accessible:

[root@***** v1]# ls -lha /somepath/uploads/billingExport.pdf
-rw-r-----. 1 root root 184 Oct 19 12:44 /somepath/uploads/billingExport.pdf

code :

$conn_id = ftp_connect($ftp_server);
if (!$conn_id)
{
    FLog("ftp_connect could not connect to FTP '".$ftp_server."'");
}
else
{
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    if (!$login_result)
    {
        FLog("Could not login to FTP with user '".$ftp_user_name."'");
    }
    else
    {
        if(!ftp_pasv($conn_id, true))
        {
            FLog("Could not switch to passive mode");
        }
        else if (ftp_put($conn_id, $fileName, LOCAL_FOLDER."/billingExport.pdf", FTP_ASCII)) 
        {
            echo "File '".$fileName."' uploaded";
        } 
        else {
            echo "Could not upload file '".$fileName."'";
        }
        ftp_close($conn_id);
    }
}

any help appreciated

thanks

[edit]

rh-php70.x86_64                2.3-1.el7           @repo.php7-MAriadb10
rh-php70-php.x86_64            7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-cli.x86_64        7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-common.x86_64     7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-json.x86_64       7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-mbstring.x86_64   7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-mysqlnd.x86_64    7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-pdo.x86_64        7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-pear.noarch       1:1.10.1-3.el7      @repo.php7-MAriadb10
rh-php70-php-process.x86_64    7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-xml.x86_64        7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-php-zip.x86_64        7.0.10-2.el7        @repo.php7-MAriadb10
rh-php70-runtime.x86_64        2.3-1.el7           @repo.php7-MAriadb10

标签: php ftp
1条回答
唯我独甜
2楼-- · 2019-06-14 15:41

it was a php issue

the error is remote fs related

I added a directory and it worked

if(!file_exists(LOCAL_FOLDER."/billingExport.pdf"))
{
    FLog("File '".LOCAL_FOLDER."/billingExport.pdf"."' does not exist");
}
else
{
    $ftp_server="XXXX";
    if($phase!=PHASE_PROD)
    {
        $ftp_user_name="YYY";
        $ftp_user_pass="XXXXX";
    }
    else
    {   
        $ftp_user_name="YYY";
        $ftp_user_pass="XXX";
    }

    $conn_id = ftp_connect($ftp_server);
    if (!$conn_id)
    {
        FLog("ftp_connect could not connect to FTP '".$ftp_server."'");
    }
    else
    {
        $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
        if (!$login_result)
        {
            FLog("Could not login to FTP with user '".$ftp_user_name."'");
        }
        else
        {
            if(!ftp_pasv($conn_id, true))
            {
                FLog("Could not switch to passive mode");
            }
            else if (ftp_put($conn_id, $remoteFileName, $localFileName, FTP_ASCII)) 
            {
                FLog("File '".$localFileName."' uploaded");
            } 
            else {
                Flog("Could not upload file '".$localFileName."'");
            }
            ftp_close($conn_id);
       }
    }
}
查看更多
登录 后发表回答