我尝试使用ftp_put()上传文件,它似乎没有找到路径,它在CLI上运行,并且将在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'
文件在那里,应该可以访问:
[root@***** v1]# ls -lha /somepath/uploads/billingExport.pdf
-rw-r-----. 1 root root 184 Oct 19 12:44 /somepath/uploads/billingExport.pdf
代码:
$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);
}
}
任何帮助表示赞赏
谢谢
[编辑]
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
答案 0 :(得分:0)
这是一个php问题
错误与远程fs相关
我添加了一个目录,它可以工作
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);
}
}
}