Hi!

I have to upload a file to a separate server and I was given access to its ftp. But to be able to access the ftp, I need ftp over ssl explicit. I tried to use curl to connect to ftp. I was able to pass through the 220 that appears just like when connecting using filezilla, but I cannot seem to login. here's the code I'm using:

        error_reporting(E_ALL);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, "ftp.example.com:21");

        curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
        curl_setopt($curl, CURLOPT_USERPWD, "user:password");
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); 
        curl_setopt($curl, CURLOPT_FTP_SSL, CURLOPT_FTPSSLAUTH);
        curl_setopt($curl, CURLOPT_SSLVERSION, 3);

        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_FTP_USE_EPSV, 1);

        $result = curl_exec($curl);
        $error_no = curl_errno($curl);


        $tuData = curl_exec($curl); 
        if(!curl_errno($curl)){ 
          $info = curl_getinfo($curl); 
          echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url']; 
        } else { 
          echo 'Curl error: ' . curl_error($curl); 
        } 

But this results to:
220- ...
220- ...
220 ...
530 Please login with USER and PASS 504 unknown security mechanism 504 unknown host

Took 0.462022 seconds to send a request to HTTP://ftp.example.com:21

Tried to access this using filezilla and I was able to.
Any ideas? Thanks :)

Recommended Answers

From what I've read you need the URL to be the full path to the file.

ftp://ftp.example.com/path/file.ext

or even:

ftp://user:password@ftp.example.com/path/file.ext
Jump to Post

All 2 Replies

I tried adding the path to file, but still same the error: Server denied you to change to the given directory appeared.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.