2012-04-10 21 views
2

Ich benutze curl php API, um auf FTP-Links zuzugreifen. Auf einer bestimmten Site gibt es Fehlercode 9 (Zugriff verweigert). Der Link ist jedoch von IE und Firefox aus zugänglich.curl FTP-Zugriff verweigert

Dann laufe ich curl-Befehlszeile und es gab die gleichen "access denieded" Ergebnisse.

> 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 

Aber der Link funktioniert gut in Firefox. Was ist hier falsch mit cUrl? Dank

+0

Wenn Sie einen vollständigen Pfad zu einem Verzeichnis angeben, macht das einen Unterschied machen? – tcole

Antwort

0

es hat nichts mit CURL die Fehler zu tun, sehr explizit Server denied you to change to the given directory waren ... Es ist einfach ein Zugang Ausgabe ...

Hinzufügen username und password einfach das Problem lösen ...

Warum es funktioniert im Browser ... Es gibt keine automatische Verzeichnisumleitung. Warum funktioniert es nicht bei curl ??? würde verwenden Standard ftp Prozess curl die Anmeldung beinhalten würde, bevor Sie entsprechende Verzeichnis

ändern können Sie, was es über PHP-Code direkt verwenden .... fopen oder file_get_content ist ein Betrüger i ... verwenden funktioniert, als ob Ihr zugreifen es via Browser

Beispiel

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

funktioniert wie Charme

2

Versuchen mit curl die Option Hantieren --ftp-Methode

--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'. 
Verwandte Themen