dpmrakfbx820320638 2014-09-09 13:42
浏览 94
已采纳

为什么我看到php ftp函数和其他客户端中的ftp功能之间存在这些差异?

I am currently on a mac, when I use the command line client to connect to an ftp server it works and I see two folders Arkiv and Saxo, I see the same thing if I go in the browser.

In drupal I have a cron hook where I use the php ftp functions. I am of course using the same username, password as the two other cases here is a sample of the code

       if (@ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)) {

         $listing = ftp_rawlist($conn_id, ".");
         watchdog('ftp root current directory', ftp_pwd($conn_id),array(), WATCHDOG_WARNING);
         watchdog('ftp root directory listing', print_r($listing,true),array(), WATCHDOG_WARNING);
         watchdog('ftp root try to change directory',$dir,array(), WATCHDOG_WARNING);

         $filecount = 0;
         if (ftp_chdir($conn_id, $dir)) {
            $contents = ftp_rawlist($conn_id, ".");
            watchdog('inside contents', print_r($contents,true), array(), WATCHDOG_WARNING);
            watchdog('inside contents and current folder', ftp_pwd($conn_id), array(), WATCHDOG_WARNING);
...
}}

the variable $dir is set to be the name of one of these folders I am expecting to see - in this case 'Arkiv', and this folder has a few hundred files in it when I look on the command line or in the browser.

The messages I receive back from this process are:

inside contents and current folder  09/09/2014 - 15:19  /Arkiv  Anonymous (not verified)    
inside contents 09/09/2014 - 15:19      Anonymous (not verified)    

ftp root try to change directory    09/09/2014 - 15:18  Arkiv   Anonymous (not verified)    
ftp root directory listing  09/09/2014 - 15:18      Anonymous (not verified)    
ftp root current directory  09/09/2014 - 15:18  /   Anonymous (not verified)

I do not seem to be able to get any content back when I try to list the directory contents. I have tried both rawlist and nlist, and neither one gives me any content back, both in the root directoy where I should have the two subdirectories Arkiv and Saxo, and in the subdirectories themselves where there are a few hundred files (confirmed from command line and browser).

furthermore, if the output from $listing = ftp_rawlist($conn_id, "."); is empty, how can it be that when I do

if (ftp_chdir($conn_id, $dir)) { .. }

that it allows me through and

ftp_pwd($conn_id)

tells me I am in the '/Arkiv' folder?

  • 写回答

1条回答

  • doupang5433 2014-09-11 07:49
    关注

    The difference is caused by being inside of a virtual machine with NAT and various firewalls, in that situation should use ftp_pasv http://php.net/manual/en/function.ftp-pasv.php which I was, unfortunately I was calling it before the login, when the documentation specifies it should be called after the login.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料