Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl FTP access denied

Tags:

curl

libcurl

I am using curl php API to access FTP links. On a particular site, it gives error code 9 (access denied). However the link is accessible from IE and Firefox.

Then I run curl command line and it gave the same "access deinied" results.

> 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 [email protected] < 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

But the link works fine in Firefox. What is wrong with cUrl here? Thanks

like image 749
cuteCAT Avatar asked Apr 10 '12 17:04

cuteCAT


2 Answers

Try fiddling with curl's option --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'.
like image 120
Daniel Stenberg Avatar answered Sep 30 '22 14:09

Daniel Stenberg


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.

like image 33
Netsanet Gebremedhin Avatar answered Sep 30 '22 14:09

Netsanet Gebremedhin