6

我正在使用 curl php API 来访问 FTP 链接。在特定站点上,它给出错误代码 9(拒绝访问)。但是,可以从 IE 和 Firefox 访问该链接。

然后我运行 curl 命令行,它给出了相同的“拒绝访问”结果。

> d:>\curl -v ftp://ftp1.example.com/outgoing/EHF/dbex10win_en.zip
> * About to connect() to ftp1.example.com port 21 (#0)
> *   Trying 204.50.113.145...
> * connected
> * Connected to ftp1.example.com (204.50.113.145) port 21 (#0) < 220 Microsoft FTP Service
> > USER anonymous < 331 Anonymous access allowed, send identity (e-mail name) as password.
> > PASS ftp@example.com < 230-Welcome to Example FTP site! < 230 Anonymous user logged in.
> > PWD < 257 "/" is current directory.
> * Entry path is '/'
> > CWD outgoing < 550 outgoing: Access is denied.
> * Server denied you to change to the given directory
> * Connection #0 to host ftp1.example.com left intact curl: (9) Server denied you to change to the given directory
> > QUIT < 221
> * Closing connection #0

但该链接在 Firefox 中运行良好。cUrl 这里有什么问题?谢谢

4

3 回答 3

7

尝试摆弄 curl 的选项 --ftp-method

   --ftp-method [method]
          (FTP) Control what method curl should use to reach a file on  a
          FTP(S) server. The method argument should be one of the follow‐
          ing alternatives:

          multicwd
                 curl does a single CWD operation for each path  part  in
                 the given URL. For deep hierarchies this means very many
                 commands. This is how RFC 1738 says it should  be  done.
                 This is the default but the slowest behavior.

          nocwd  curl  does  no CWD at all. curl will do SIZE, RETR, STOR
                 etc and give a full path to the  server  for  all  these
                 commands. This is the fastest behavior.

          singlecwd
                 curl  does  one  CWD  with the full target directory and
                 then operates on the file "normally" (like in the multi‐
                 cwd  case).  This  is  somewhat more standards compliant
                 than 'nocwd' but without the full penalty of 'multicwd'.
于 2012-04-17T22:45:33.500 回答
0

它与错误无关CURL 非常明确Server denied you to change to the given directory......它只是一个访问问题......

添加usernamepassword简单地解决问题...

为什么它可以在浏览器上运行......没有自动目录重定向..为什么它不能在 curl 上运行???curl 将使用标准 ftp过程,该过程将在您更改到相关目录之前涉及登录

您可以通过 php 直接使用它....fopen或者file_get_content是我使用的作弊器...就像您通过浏览器访问它一样工作

例子

 set_time_limit(0);
 file_put_contents("out.zip", file_get_contents('ftp://204.50.113.145/outgoing/EHF/dbex10win_en.zip'));

像魅力一样工作

于 2012-04-10T23:02:01.970 回答
0

That means the specified directory does not exist in the remote/ftp server, hence the message "Server denied you to change to the given directory".

That message has got nothing to do with the local machine you are trying to download files into.

Login to ftp datacenter.myserver.com and see if the source directory exists.

于 2019-01-11T15:31:49.847 回答