使用Php将文件从FTP服务器复制到Cpanel
你能帮助我吗。我正在尝试将文件复制到应用程序内的文件夹中。该脚本正在我的本地计算机上运行,但是当我在Cpanel服务器上运行它时,它显示一个错误“ftp_login()期望参数1是资源,给定布尔值” 这是我测试的脚本使用Php将文件从FTP服务器复制到Cpanel,php,ftp-server,Php,Ftp Server,你能帮助我吗。我正在尝试将文件复制到应用程序内的文件夹中。该脚本正在我的本地计算机上运行,但是当我在Cpanel服务器上运行它时,它显示一个错误“ftp_login()期望参数1是资源,给定布尔值” 这是我测试的脚本 $folder_path = "192.xx.xx.xx\TMS"; $local_file = "CurrentFile\Inbound.xls"; $server_file = "CurrentFile\Inbound.xls"; //-- C
$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);
我认为脚本无法连接到FTP服务器。
如果我在创建连接后添加此项,它将返回“连接失败”
我不习惯这一点,但我建议去本教程,让我知道这会发生什么谢谢Amit的回复!不幸的是,教程不是我需要的。它会在脚本登录到FTP服务器之前检查连接是否成功,以避免出现如下错误:“警告:FTP_login()希望参数1为resource,第65行的/home/content/98/10339998/html/upload.php中给出的布尔值FTP连接遇到错误!试图连接到LegendMaker.net…”
if(!$conn_id) {
die("Connection failed!");
}