как отправить файл на ftp через прокси

Discussion in 'PHP' started by Student :), 8 Jan 2010.

  1. Student :)

    Student :) Elder - Старейшина

    Joined:
    9 Feb 2007
    Messages:
    278
    Likes Received:
    18
    Reputations:
    -15
    С прошедшими!
    как отправить файл на ftp через прокси с авторизацией?
    делаю так
    PHP:
    $localfile = "1.html";
    $ftpserver = "ftp.narod.ru";
    $ftppath   = "";
    $ftpuser   = "1";
    $ftppasswd   = "22";

    $remoteurl = "ftp://${ftpuser}:${ftppasswd}@${ftpserver}${ftppath}/${localfile}";

    $ch = curl_init();

    $fp = fopen($localfile, "rb");

    // we upload a JPEG image
    curl_setopt($ch, CURLOPT_PROXY, '10.1.1.1:8080');
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:pass');
    curl_setopt($ch, CURLOPT_URL, $remoteurl);
    curl_setopt($ch, CURLOPT_PUT, 1); 
    curl_setopt($ch, CURLOPT_UPLOAD, 1);
    curl_setopt($ch, CURLOPT_FTPASCII, 1);
    curl_setopt($ch, CURLOPT_INFILE, $fp);

    // set size of the image, which isn't _mandatory_ but helps libcurl to do
    // extra error checking on the upload.
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));

    curl_exec($ch);

    echo 
    "<pre>";
    print_r(curl_getinfo($ch));
    echo 
    "\n cURL error number:" .curl_errno($ch);
    echo 
    "\n cURL error:" . curl_error($ch);  
    // check $error here to see if it did fine or not!

    curl_close($ch);