为什么我看到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个回答



差异是由于在具有NAT和各种防火墙的虚拟机内部引起的,在这种情况下应该使用ftp_pasv http://php.net/manual/en/function.ftp-pasv.php 不幸的是,我在登录前调用它,当文档指定应该在登录后调用它。 </ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问