欢迎来到云服务器

Directadmin Linux面板

如何将ftp_upload.php转换为使用ncftpput或curl而不是php

请注意,本指南已经变老,应该只使用生成指南来了解如何编辑ftp_upload.php。
如果您选择FTPS,我们较新的ftp_upload.php支持curl,如果您只选择FTP,则使用php上传。
 
在某些情况下,使用以下脚本可能会有效,但也可能会中断“追加到路径”选项,因为它们不会正确处理它,导致备份如下:

Mondayuser.admin.fred.tar.gz

这是不正确的。


php支持ftp上传...这是DA用于将文件上传到远程ftp服务器的内容。
在某些情况下,由php生成的错误不足以调试ftp问题,因此将此脚本转换为使用不同的ftp客户端可能会有所帮助。
 
你可以转换:
/usr/local/directadmin/scripts/ftp_upload.php
 
使用curl而不是php,首先将它复制到:
/usr/local/directadmin/scripts/custom/ftp_upload.php
 
并使副本的内容如下所示:

/bin/sh
# CURL Backup Transfer
# Version 0.1a
# Copyright 2006, Sensson (www.sensson.net)
#
# This script makes it possible to transfer
# backups using your secondary uplink
# like eth1.

ETH=eth0
CURL=/usr/local/bin/curl

result=`$CURL --interface $ETH -T $ftp_local_file -u $ftp_username:$ftp_password ftp://$ftp_ip$ftp_path$ftp_remote_file 2>&1`

if grep -q -o -i "curl: (67) Access denied: 530.*$" <<< "$result"; then
          echo "FTP access denied. Please check your login details."
          exit 1
fi
if grep -q -o -i "curl: (6) Couldn't resolve host.*$" <<< "$result"; then
          echo "Host could not be resolved. Please check your host details."
          exit 1
fi
if grep -q -o -i "curl: (9) Uploaded unaligned file size.*$" <<< "$result"; then
          echo "File could not be uploaded. Please check your path."
          exit 1
fi
if grep -q -o -i "curl: Can't open.*$" <<< "$result"; then
          echo "Can't open $ftp_local_file"
          exit 1
fi

务必将ETH值适当地设置到您的网络设备。
此外,ftp_path值必须有一个结尾斜杠才能正常工作。
 
如果您不需要指定curl绑定到的任何接口,则可以删除该命令的--interface $ ETH部分。
 
从这里引用
 
可以使用相同的方法将脚本转换为ncftpput而不是curl或php。
编辑ftp_upload.php脚本并插入以下代码:

/bin/sh
/usr/bin/ncftpput -t 25 -m -u "$ftp_username" -p "$ftp_password" "$ftp_ip" "$ftp_path" "$ftp_local_file" 2>&1
RET=$?
exit $RET



最后,这个设置的原始方法是使用php:

/usr/local/bin/php
<?

$use_pasv = true;

$ftp_server = getenv("ftp_ip");
$ftp_user_name = getenv("ftp_username");
$ftp_user_pass = getenv("ftp_password");
$ftp_remote_path = getenv("ftp_path");
$ftp_remote_file = getenv("ftp_remote_file");
$ftp_local_file = getenv("ftp_local_file");

$conn_id = ftp_connect($ftp_server);
if (!$conn_id)
{
          echo "Unable to connect to $ftp_servern";
          exit(1);
}

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if (!$login_result)
{
          echo "Inavalid login/password for $ftp_user_name on $ftp_server";
          ftp_close($conn_id);
          exit(2);
}

ftp_pasv($conn_id, $use_pasv);

ftp_mkdir($conn_id, $ftp_remote_path);

if (!ftp_chdir($conn_id, $ftp_remote_path))
{
          echo "Invalid remote path '$ftp_remote_path'";
          ftp_close($conn_id);
          exit(3);
}

if (ftp_put($conn_id, $ftp_remote_file, $ftp_local_file, FTP_BINARY))
{
          ftp_close($conn_id);
          exit(0);
}
else
{
          $use_pasv = false;

          ftp_pasv($conn_id, $use_pasv);

          if (ftp_put($conn_id, $ftp_remote_file, $ftp_local_file, FTP_BINARY))
          {
                    ftp_close($conn_id);
                    exit(0);
          }
          else
          {
                    ftp_close($conn_id);
                    echo "Error while uploading $ftp_remote_file";
                    exit(4);
          }
}

?>

腾讯云代理

Copyright © 2003-2021 MFISP.COM. 国外vps服务器租用 梦飞云服务器租用 版权所有 粤ICP备11019662号