简体   繁体   English

从 ftp 下载文件到 codeigniter 2 使用 FTP Class

[英]Downloading file from ftp in codeigniter 2 using FTP Class

I want to download some file from FTP Server using FTP Class that already in CodeIgniter, but i get error ftp_get() failed to open stream: permission denied when i called my code.我想使用 FTP 服务器使用 FTP Class 下载一些已经在 CodeIgniter 中的文件,但我收到错误 ftp_get() 无法打开 stream:调用我的代码时权限被拒绝。 anyone can help me, please?任何人都可以帮助我吗?

this is my code这是我的代码

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class C_FTP extends CI_Controller 
{
public function openfile($fileName)
{
    $this->load->library('ftp');
    $config['hostname'] = 'ftp_host';
    $config['username'] = 'ftp_username';
    $config['password'] = 'ftp_password';
    $config['port']     = 'ftp_port';
    $config['debug']    = FALSE;
    $config['passive']  = FALSE;
    $this->ftp->connect($config);
    $this->ftp->download('path/to/folder/', 'local/path', 'auto');
    $this->ftp->close();
}}
?>

and my ci version is: 2.2.0我的 ci 版本是:2.2.0

I have found the solution of my problem, just add header before you download the file this my code:我找到了我的问题的解决方案,只需在下载我的代码文件之前添加 header:

before

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class C_FTP extends CI_Controller 
{
public function openfile($fileName)
{
    $this->load->library('ftp');
    $config['hostname'] = 'ftp_host';
    $config['username'] = 'ftp_username';
    $config['password'] = 'ftp_password';
    $config['port']     = 'ftp_port';
    $config['debug']    = FALSE;
    $config['passive']  = FALSE;
    $this->ftp->connect($config);
    $this->ftp->download('path/to/folder/', 'local/path', 'auto');
    $this->ftp->close();
}}
?>

change with this改变这个


<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class C_FTP extends CI_Controller 
{
public function openfile($fileName)
{
    $this->load->library('ftp');
    $config['hostname'] = 'ftp_host';
    $config['username'] = 'ftp_username';
    $config['password'] = 'ftp_password';
    $config['port']     = 'ftp_port';
    $config['debug']    = FALSE;
    $config['passive']  = FALSE;
    $this->ftp->connect($config);
    header('Content-type: text/plain');
    header('Content-Disposition: attachment; filename="filename.pdf"');
    $this->ftp->download('path/to/folder/', 'local/path', 'auto');
    $this->ftp->close();
}}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM