Petar Koretić | 8 Dec 14:57
Picon

PHP - CURL - Microsoft Sharepoint Server 2010 - Authorization

About my server support that i think is relevant
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHP Version 5.3.3-7+squeeze3
CURL : 7.21.0
Features
NTLM Yes
Protocols dict, file, ftp, ftps, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

i'm trying to connect to a SharePoint site which requires authorization that, truthfully, i don't know nothing about anymore, it seems like it's modified (same user and pass for all of us, not local, 'remember me' doesn't work)
anyway, i used libcurl many times and had no problem on various sites, and google and documentation say i should have much of a problem now neither

the problem i'm facing is that curl doesn't post, i don't even get an error, php just echoes page back even if i use same code i used on other sites for authentication

(i can provide code i'm using but i don't think that would do much)

so how do i make successful authorization (or even failed post) based on this real request (this is real data made by browser, user and password aren't of course)
this is successful post with source option rather than parsed
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1. Request URL:
  2. Request Method:
    POST
  3. Status Code:
    302 Found
  4. Request Headersview parsed
    1. POST /_layouts/login.aspx?ReturnUrl=%2f HTTP/1.1 Host: wssim.t.ht.hr Connection: keep-alive Content-Length: 818 Cache-Control: max-age=0 Origin: https://wssim.t.ht.hr User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2 Content-Type: application/x-www-form-urlencoded Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Referer: https://wssim.t.ht.hr/_layouts/login.aspx?ReturnUrl=%2f Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  5. Query String Parametersview URL encoded
    1. ReturnUrl:
      /
  6. Form Dataview URL encoded
    1. __LASTFOCUS:
    2. __VIEWSTATE:
      /wEPDwUKMTc0NDQ2ODg4OQ9kFgJmD2QWAmYPZBYCAgMPZBYCAjUPZBYCAgEPPCsACgEADxYCHghVc2VyTmFtZQUEdGVzdGQWAmYPZBYGAgEPDxYCHgRUZXh0BYABUG9zbHXFvml0ZWxqIHZhcyBuaWplIG1vZ2FvIHByaWphdml0aS4gUHJvdmplcml0ZSBqZXN0ZSBsaSB1bmlqZWxpIGlzcHJhdm5vIGtvcmlzbmnEjWtvIGltZSBpIGxvemlua3UgaSB6YXRpbSBwb2t1xaFhanRlIHBvbm92by5kZAIFDw8WAh8BBQR0ZXN0ZGQCDQ8QDxYCHgdDaGVja2VkaGRkZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFJmN0bDAwJFBsYWNlSG9sZGVyTWFpbiRsb2dpbiRSZW1lbWJlck1lbfiRaFA/QrH2xtLcNAnzU9alXhs=
    3. __EVENTTARGET:
    4. __EVENTARGUMENT:
    5. __EVENTVALIDATION:
      /wEWBQKOlpeQBwLE96mtBQLLtsPBAgLkkP7MCgK/lZyyB7lmGymvBTkJ 5Kj2eetXLC6PRyy
    6. ctl00$PlaceHolderMain$login$UserName: user
    7. ctl00$PlaceHolderMain$login$password: password
    8. ctl00$PlaceHolderMain$login$login:
      Prijava
    9. __spDummyText1:
    10. __spDummyText2:
  7. Response Headersview parsed
    1. HTTP/1.1 302 Found Cache-Control: private Content-Length: 9422 Content-Type: text/html; charset=utf-8 Location: / Server: Microsoft-IIS/7.0 X-AspNet-Version: 2.0.50727 Set-Cookie: .ASPXAUTH=7B91D01172F6C5F5215071BFBA499E9D97E7E2C75A88CDBC41B3EE99DFABFC623338D0FB7794B39D33251703FAFECEFEDAC1A74AE2E0EF1DD93E3861CA768E6D919CF7098248DA74A65FF4B5F38554CF45C48460FCCBEA836EC34D195709D55EC536BF1E322DF336B421CFD2087247D6CC14E93D; path=/; HttpOnly X-Powered-By: ASP.NET MicrosoftSharePointTeamServices: 12.0.0.6421 Date: Thu, 08 Dec 2011 13:24:14 GMT
----------------------------------------------------------------------------------------------------------------------------------
and this is the unsuccessful request (no user&pass in input fields)
parsed options
---------------------------------------------------------------------------------------------------------------------------------
  1. Request URL:
  2. Request Method:
    POST
  3. Status Code:
    200 OK
  4. Request Headersview source
    1. Accept:
      text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    2. Accept-Charset:
      ISO-8859-1,utf-8;q=0.7,*;q=0.3
    3. Accept-Encoding:
      gzip,deflate,sdch
    4. Accept-Language:
      en-US,en;q=0.8
    5. Cache-Control:
      max-age=0
    6. Connection:
      keep-alive
    7. Content-Length:
      558
    8. Content-Type:
      application/x-www-form-urlencoded
    9. Host:
    10. Origin:
    11. Referer:
    12. User-Agent:
      Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2
  5. Query String Parametersview URL encoded
    1. ReturnUrl:
      /
  6. Form Dataview URL encoded
    1. __LASTFOCUS:
    2. __VIEWSTATE:
      /wEPDwUKMTc0NDQ2ODg4OQ9kFgJmD2QWAmYPZBYCAgMPZBYCAjUPZBYCAgEPZBYCZg9kFgICDQ8QDxYCHgdDaGVja2VkaGRkZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFJmN0bDAwJFBsYWNlSG9sZGVyTWFpbiRsb2dpbiRSZW1lbWJlck1lyBvugVHSL6dRxUgDGmWJOn4ReLo=
    3. __EVENTTARGET:
    4. __EVENTARGUMENT:
    5. __EVENTVALIDATION:
      /wEWBQK/vPf6CwLE96mtBQLLtsPBAgLkkP7MCgK/lZyyBzrGvaVwXdg1oTe7Cm Th3D/RMdY
    6. ctl00$PlaceHolderMain$login$UserName:
    7. ctl00$PlaceHolderMain$login$password:
    8. ctl00$PlaceHolderMain$login$login:
      Prijava
    9. __spDummyText1:
    10. __spDummyText2:
  7. Response Headersview source
    1. Cache-Control:
      private
    2. Content-Encoding:
      gzip
    3. Content-Length:
      3912
    4. Content-Type:
      text/html; charset=utf-8
    5. Date:
      Thu, 08 Dec 2011 13:36:00 GMT
    6. MicrosoftSharePointTeamServices:
      12.0.0.6421
    7. Server:
      Microsoft-IIS/7.0
    8. Vary:
      Accept-Encoding
    9. X-AspNet-Version:
      2.0.50727
    10. X-Powered-By:










_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
David Colter | 8 Dec 17:31
Picon
Favicon

Re: PHP - CURL - Microsoft Sharepoint Server 2010 - Authorization

Hi

the problem i'm facing is that curl doesn't post, i don't even get an error, php just echoes page back even if i use same code i used on other sites for authentication

(i can provide code i'm using but i don't think that would do much)

so how do i make successful authorization (or even failed post) based on this real request (this is real data made by browser, user and password aren't of course)
this is successful post with source option rather than parsed

We will need your code to understand your question & request. 

David 
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Petar Koretić | 8 Dec 17:49
Picon

Re: PHP - CURL - Microsoft Sharepoint Server 2010 - Authorization

this is the code that works when I use it with other server accessible only from our network (intranet)
------------------------------------------------------------------------------------------------------------------------------------------------------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "j_username=local_username&j_password=local_password");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_MAXREDIRS,10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.23 (Windows NT 5.1; U; en)');

curl_exec ($ch); 
------------------------------------------------------------------------------------------------------------------------------------------------------------
but when i change address and  set it to what was in the first message (adress that is accessible from everywhere, everybody can try to login with false data) and test it, the page is then just displayed, nothing happens, no posting as i can see and no errors

so i've tried more and more 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
$POSTFIELDS = 'ctl00$PlaceHolderMain$login$login=Prijava'; //i've tried with all post fields that are needed but it's the same as with one

$ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.23 (Windows NT 5.1; U; en)');
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_MAXREDIRS,10);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
curl_setopt($ch,CURLOPT_USERPWD,"user:pass"); 
    $result = curl_exec ($ch);
------------------------------------------------------------------------------------------------------------------------------------------------------------

but no luck...of course, i've tried many things, but i fear i'm probably heading in the wrong direction with more options...

------------------------------------------------------------------------------------------------------------------------------------------------------------

On Thu, Dec 8, 2011 at 5:31 PM, David Colter <dolan2go <at> yahoo.com> wrote:
Hi

the problem i'm facing is that curl doesn't post, i don't even get an error, php just echoes page back even if i use same code i used on other sites for authentication

(i can provide code i'm using but i don't think that would do much)

so how do i make successful authorization (or even failed post) based on this real request (this is real data made by browser, user and password aren't of course)
this is successful post with source option rather than parsed

We will need your code to understand your question & request. 

David 

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php


_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
-Sys Adm- | 16 Dec 02:41
Picon
Favicon

Reading/Writing to the same file via FTP...

All I need to do in PHP is:

READ the contents of a file on my FTP server.  (Contents of file are only a single number, 0 - 12)
Add that to a $variable string
Change that $variable and re-write the contents to the same file I READ from.

I am currently READING the contents of the file and adding that to a $variable perfectly using this function:

$expire = "filename";

function read_file($expire)
        {
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, "ftp://"location"/".$expire);
            curl_setopt($curl, CURLOPT_USERPWD, "U:P");
            curl_setopt($curl, CURLOPT_HEADER, 0);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
            curl_setopt($curl, CURLOPT_TIMEOUT, 20);
            $data = curl_exec($curl);
            curl_close($curl);
            if ($data != false){
                return $data;
                }else{
                echo 'ERROR';
               }
        }
            $content = read_file($expire);


As far as WRITING the $new_content variable back to the same file, I am completely lost on finding any examples of this....

My assumption would be:

$expire = "filename";
$content = $new_contents;

function write_file($expire)
           $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, "ftp://"location"/".$expire);
            curl_setopt($curl, CURLOPT_USERPWD, "U:P");
            curl_setopt($curl, CURLOPT_HEADER, 0);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    //this is where I am completely lost...
            curl_setopt($curl, CURLOPT_WRITEFUNCTION, "$new_contents?");
            curl_setopt($curl, CURLOPT_WRITEDATA, "$new_contents?");
    //
            curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
            curl_setopt($curl, CURLOPT_TIMEOUT, 20);
            $data = curl_exec($curl);
            curl_close($curl);
            if ($data != false){
                return $data;
                }else{
                echo 'ERROR';
                }
        }


I have read that cURL does NOT need the fopen, fwrite, fclose calls in order to write data to a file? And I have also read about the CURLOPT_WRITEFUNCTION call, and that is where I am not sure how to WRITE the new contents of the $new_contents variable???

A simple example on the cURL PHP example would be wonderful.

I apologize in advance for my lack of PHP or cURL knowledge.  I am working on this project for a commercial business, and I am the smartest one employed here!!

Thanks in advance...
SysAdm






_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Shiplu | 16 Dec 07:04
Picon
Gravatar

Re: Reading/Writing to the same file via FTP...

You need to write the file on local disk first. Then upload it to ftp.
I have modified your code. See in line bellow.

On Fri, Dec 16, 2011 at 7:41 AM, -Sys Adm- <centralsource <at> hotmail.com> wrote:
>
> All I need to do in PHP is:
>
> READ the contents of a file on my FTP server.  (Contents of file are only a single number, 0 - 12)
> Add that to a $variable string
> Change that $variable and re-write the contents to the same file I READ from.
>
> I am currently READING the contents of the file and adding that to a $variable perfectly using this function:
>
> $expire = "filename";
>
> function read_file($expire)
>         {
>             $curl = curl_init();
>             curl_setopt($curl, CURLOPT_URL, "ftp://"location"/".$expire);
>             curl_setopt($curl, CURLOPT_USERPWD, "U:P");
>             curl_setopt($curl, CURLOPT_HEADER, 0);
>             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
>             curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
>             curl_setopt($curl, CURLOPT_TIMEOUT, 20);
>             $data = curl_exec($curl);
>             curl_close($curl);
>             if ($data != false){
>                 return $data;
>                 }else{
>                 echo 'ERROR';
>                }
>         }
>             $content = read_file($expire);
>
>
> As far as WRITING the $new_content variable back to the same file, I am completely lost on finding any
examples of this....
>
> My assumption would be:
>
> $expire = "filename";
> $content = $new_contents;
>
> function write_file($expire)
        $ch = curl_init();
        $fp = fopen($expire, 'r');
 	curl_setopt($ch, CURLOPT_URL,
'ftp://ftp_login:password <at> ftp.domain.com/'.$expire);
 	curl_setopt($ch, CURLOPT_UPLOAD, 1);
 	curl_setopt($ch, CURLOPT_INFILE, $fp);
 	curl_setopt($ch, CURLOPT_INFILESIZE, filesize($expire));
        fclose($fp);

>             curl_exec($curl);
 	$data = curl_errno($ch);
>             curl_close($curl);
>             if ($data != false){
>                 return $data;
>                 }else{
>                 echo 'ERROR';
>                 }
>         }
>
>

--
Shiplu Mokaddim
Talks: http://shiplu.mokadd.im
Follow: http://twitter.com/shiplu
Innovation distinguishes between follower and leader

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

-Sys Adm- | 16 Dec 17:19
Picon
Favicon

RE: Reading/Writing to the same file via FTP...



> Date: Fri, 16 Dec 2011 12:04:30 +0600
> Subject: Re: Reading/Writing to the same file via FTP...
> From: shiplu.net <at> gmail.com
> To: curl-and-php <at> cool.haxx.se
>
> You need to write the file on local disk first. Then upload it to ftp.
> I have modified your code. See in line bellow.
>
> On Fri, Dec 16, 2011 at 7:41 AM, -Sys Adm- <centralsource <at> hotmail.com> wrote:
> >
> > All I need to do in PHP is:
> >
> > READ the contents of a file on my FTP server.  (Contents of file are only a single number, 0 - 12)
> > Add that to a $variable string
> > Change that $variable and re-write the contents to the same file I READ from.
> >
> > I am currently READING the contents of the file and adding that to a $variable perfectly using this function:
> >
> > $expire = "filename";
> >
> > function read_file($expire)
> >         {
> >             $curl = curl_init();
> >             curl_setopt($curl, CURLOPT_URL, "ftp://"location"/".$expire);
> >             curl_setopt($curl, CURLOPT_USERPWD, "U:P");
> >             curl_setopt($curl, CURLOPT_HEADER, 0);
> >             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
> >             curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
> >             curl_setopt($curl, CURLOPT_TIMEOUT, 20);
> >             $data = curl_exec($curl);
> >             curl_close($curl);
> >             if ($data != false){
> >                 return $data;
> >                 }else{
> >                 echo 'ERROR';
> >                }
> >         }
> >             $content = read_file($expire);
> >
> >
> > As far as WRITING the $new_content variable back to the same file, I am completely lost on finding any examples of this....
> >
> > My assumption would be:
> >
> > $expire = "filename";
> > $content = $new_contents;
> >
> > function write_file($expire)
> $ch = curl_init();
> $fp = fopen($expire, 'r');
> curl_setopt($ch, CURLOPT_URL,
> 'ftp://ftp_login:password <at> ftp.domain.com/'.$expire);
> curl_setopt($ch, CURLOPT_UPLOAD, 1);
> curl_setopt($ch, CURLOPT_INFILE, $fp);
> curl_setopt($ch, CURLOPT_INFILESIZE, filesize($expire));
> fclose($fp);
>
> >             curl_exec($curl);
> $data = curl_errno($ch);
> >             curl_close($curl);
> >             if ($data != false){
> >                 return $data;
> >                 }else{
> >                 echo 'ERROR';
> >                 }
> >         }
> >
> >
>
>
>
> --
> Shiplu Mokaddim
> Talks: http://shiplu.mokadd.im
> Follow: http://twitter.com/shiplu
> Innovation distinguishes between follower and leader
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php





--- This makes no sense to me that in my PHP that fopen, fwrite and fclose can work on the same file "on the fly" with a simple ftp connection call, but cURL can not? 

The whole reason I'm using cURL is for it's encrypted authentication to the FTP server.  

So basically, if I have to create the file locally with fopen on the client's host machine that is executing my PHP,  then they can just "capture" that file prior to cURL uploading it back to the FTP server?  This is not at all secure for my application.

I was having this done using a simple FTP connection with fopen, fwrite, fclose, but obviously ftp streams the username:password in clear text... again, the whole reason to use cURL. 

Surely there must be a way once I have the "captured" file contents within cURL to overwrite that  data "on the fly" and close the file back.  With nothing being created locally....

SysAdm









_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
jbarker | 16 Dec 17:22
Picon
Favicon

Re: RE: Reading/Writing to the same file via FTP...

Hi, I am currently on break from the 10th December 2011 - 19th December 2011.
 If you have an emergency request: (Please note only issues pertaining to the web server or mail server (web
site is down or not receiving mail) will be addressed.
 If you have a fault in regards to functionality of your site this will not be dealt with until I am back in the
office) 

Option 1. 
1. Send an email to support <at> netlogistics.com.au 
2. Explaining the issue or fault.
 3. Add the following information to your email also: Domain: (e.g. www.orangetree.com.au)
Server IP: 122.201.109.71
Tell tech support person to check billing account for RDP password. 

Option 2. 
1. Call 1300 NET LOG
2. Press 1 for Technical Support 
3. Explaining the issue or fault.
4. Give the following information to the tech support person: Domain: (e.g. www.orangetree.com.au)
Server IP: 122.201.109.71
Tell tech support person to check billing account for RDP password.

Option 3.
1. Send an email to support <at> orangetree.com.au

I will be back in the office on Monday 19th December 2011 

Kind regards, 
John Barker 
Director Orange Tree Design Studio

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Shanshui Liu | 16 Dec 21:01
Picon
Favicon
Gravatar

Re: Reading/Writing to the same file via FTP...

Write it to php://memory, then pass it to CURLOPT_INFILE as a stream.


If all you're sending is a file containing a number, it would be more straightforward to just set up a basic API on the receiving end and communicate over HTTPS instead of messing with FTP (you're sending the credentials in plaintext even if you're using cURL, unless you're using FTPS).

With regards,
Liu Shan Shui
http://lx.sg/
"Life would be much easier if I had the source code." - Anonymous


On Sat, Dec 17, 2011 at 12:19 AM, -Sys Adm- <centralsource <at> hotmail.com> wrote:


> Date: Fri, 16 Dec 2011 12:04:30 +0600
> Subject: Re: Reading/Writing to the same file via FTP...
> From: shiplu.net <at> gmail.com
> To: curl-and-php <at> cool.haxx.se

>
> You need to write the file on local disk first. Then upload it to ftp.
> I have modified your code. See in line bellow.
>
> On Fri, Dec 16, 2011 at 7:41 AM, -Sys Adm- <centralsource <at> hotmail.com> wrote:
> >
> > All I need to do in PHP is:
> >
> > READ the contents of a file on my FTP server.  (Contents of file are only a single number, 0 - 12)
> > Add that to a $variable string
> > Change that $variable and re-write the contents to the same file I READ from.
> >
> > I am currently READING the contents of the file and adding that to a $variable perfectly using this function:
> >
> > $expire = "filename";
> >
> > function read_file($expire)
> >         {
> >             $curl = curl_init();
> >             curl_setopt($curl, CURLOPT_URL, "ftp://"location"/".$expire);
> >             curl_setopt($curl, CURLOPT_USERPWD, "U:P");
> >             curl_setopt($curl, CURLOPT_HEADER, 0);
> >             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
> >             curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
> >             curl_setopt($curl, CURLOPT_TIMEOUT, 20);
> >             $data = curl_exec($curl);
> >             curl_close($curl);
> >             if ($data != false){
> >                 return $data;
> >                 }else{
> >                 echo 'ERROR';
> >                }
> >         }
> >             $content = read_file($expire);
> >
> >
> > As far as WRITING the $new_content variable back to the same file, I am completely lost on finding any examples of this....
> >
> > My assumption would be:
> >
> > $expire = "filename";
> > $content = $new_contents;
> >
> > function write_file($expire)
> $ch = curl_init();
> $fp = fopen($expire, 'r');
> curl_setopt($ch, CURLOPT_URL,
> 'ftp://ftp_login:password <at> ftp.domain.com/'.$expire);
> curl_setopt($ch, CURLOPT_UPLOAD, 1);
> curl_setopt($ch, CURLOPT_INFILE, $fp);
> curl_setopt($ch, CURLOPT_INFILESIZE, filesize($expire));
> fclose($fp);
>
> >             curl_exec($curl);
> $data = curl_errno($ch);
> >             curl_close($curl);
> >             if ($data != false){
> >                 return $data;
> >                 }else{
> >                 echo 'ERROR';
> >                 }
> >         }
> >
> >
>
>
>
> --
> Shiplu Mokaddim
> Talks: http://shiplu.mokadd.im
> Follow: http://twitter.com/shiplu
> Innovation distinguishes between follower and leader
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php





--- This makes no sense to me that in my PHP that fopen, fwrite and fclose can work on the same file "on the fly" with a simple ftp connection call, but cURL can not? 

The whole reason I'm using cURL is for it's encrypted authentication to the FTP server.  

So basically, if I have to create the file locally with fopen on the client's host machine that is executing my PHP,  then they can just "capture" that file prior to cURL uploading it back to the FTP server?  This is not at all secure for my application.

I was having this done using a simple FTP connection with fopen, fwrite, fclose, but obviously ftp streams the username:password in clear text... again, the whole reason to use cURL. 

Surely there must be a way once I have the "captured" file contents within cURL to overwrite that  data "on the fly" and close the file back.  With nothing being created locally....

SysAdm










_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php


_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
jbarker | 16 Dec 21:04
Picon
Favicon

Re: Re: Reading/Writing to the same file via FTP...

Hi, I am currently on break from the 10th December 2011 - 19th December 2011.
 If you have an emergency request: (Please note only issues pertaining to the web server or mail server (web
site is down or not receiving mail) will be addressed.
 If you have a fault in regards to functionality of your site this will not be dealt with until I am back in the
office) 

Option 1. 
1. Send an email to support <at> netlogistics.com.au 
2. Explaining the issue or fault.
 3. Add the following information to your email also: Domain: (e.g. www.orangetree.com.au)
Server IP: 122.201.109.71
Tell tech support person to check billing account for RDP password. 

Option 2. 
1. Call 1300 NET LOG
2. Press 1 for Technical Support 
3. Explaining the issue or fault.
4. Give the following information to the tech support person: Domain: (e.g. www.orangetree.com.au)
Server IP: 122.201.109.71
Tell tech support person to check billing account for RDP password.

Option 3.
1. Send an email to support <at> orangetree.com.au

I will be back in the office on Monday 19th December 2011 

Kind regards, 
John Barker 
Director Orange Tree Design Studio

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

-Sys Adm- | 17 Dec 00:37
Picon
Favicon

RE: Reading/Writing to the same file via FTP...




On Sat, Dec 17, 2011 at 12:19 AM, -Sys Adm- <centralsource <at> hotmail.com> wrote:


> Date: Fri, 16 Dec 2011 12:04:30 +0600
> Subject: Re: Reading/Writing to the same file via FTP...
> From: shiplu.net <at> gmail.com
> To: curl-and-php <at> cool.haxx.se

>
> You need to write the file on local disk first. Then upload it to ftp.
> I have modified your code. See in line bellow.
>
> On Fri, Dec 16, 2011 at 7:41 AM, -Sys Adm- <centralsource <at> hotmail.com> wrote:
> >
> > All I need to do in PHP is:
> >
> > READ the contents of a file on my FTP server.  (Contents of file are only a single number, 0 - 12)
> > Add that to a $variable string
> > Change that $variable and re-write the contents to the same file I READ from.
> >
> > I am currently READING the contents of the file and adding that to a $variable perfectly using this function:
> >
> > $expire = "filename";
> >
> > function read_file($expire)
> >         {
> >             $curl = curl_init();
> >             curl_setopt($curl, CURLOPT_URL, "ftp://"location"/".$expire);
> >             curl_setopt($curl, CURLOPT_USERPWD, "U:P");
> >             curl_setopt($curl, CURLOPT_HEADER, 0);
> >             curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
> >             curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
> >             curl_setopt($curl, CURLOPT_TIMEOUT, 20);
> >             $data = curl_exec($curl);
> >             curl_close($curl);
> >             if ($data != false){
> >                 return $data;
> >                 }else{
> >                 echo 'ERROR';
> >                }
> >         }
> >             $content = read_file($expire);
> >
> >
> > As far as WRITING the $new_content variable back to the same file, I am completely lost on finding any examples of this....
> >
> > My assumption would be:
> >
> > $expire = "filename";
> > $content = $new_contents;
> >
> > function write_file($expire)
> $ch = curl_init();
> $fp = fopen($expire, 'r');
> curl_setopt($ch, CURLOPT_URL,
> 'ftp://ftp_login:password <at> ftp.domain.com/'.$expire);
> curl_setopt($ch, CURLOPT_UPLOAD, 1);
> curl_setopt($ch, CURLOPT_INFILE, $fp);
> curl_setopt($ch, CURLOPT_INFILESIZE, filesize($expire));
> fclose($fp);
>
> >             curl_exec($curl);
> $data = curl_errno($ch);
> >             curl_close($curl);
> >             if ($data != false){
> >                 return $data;
> >                 }else{
> >                 echo 'ERROR';
> >                 }
> >         }
> >
> >
>
>
>
> --
> Shiplu Mokaddim
> Talks: http://shiplu.mokadd.im
> Follow: http://twitter.com/shiplu
> Innovation distinguishes between follower and leader
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php





--- This makes no sense to me that in my PHP that fopen, fwrite and fclose can work on the same file "on the fly" with a simple ftp connection call, but cURL can not? 

The whole reason I'm using cURL is for it's encrypted authentication to the FTP server.  

So basically, if I have to create the file locally with fopen on the client's host machine that is executing my PHP,  then they can just "capture" that file prior to cURL uploading it back to the FTP server?  This is not at all secure for my application.

I was having this done using a simple FTP connection with fopen, fwrite, fclose, but obviously ftp streams the username:password in clear text... again, the whole reason to use cURL. 

Surely there must be a way once I have the "captured" file contents within cURL to overwrite that  data "on the fly" and close the file back.  With nothing being created locally....

SysAdm










_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php



_______________________________________________ http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php






Date: Sat, 17 Dec 2011 04:01:31 +0800
Subject: Re: Reading/Writing to the same file via FTP...
From: me <at> lx.sg
To: curl-and-php <at> cool.haxx.se

Write it to php://memory, then pass it to CURLOPT_INFILE as a stream.

If all you're sending is a file containing a number, it would be more straightforward to just set up a basic API on the receiving end and communicate over HTTPS instead of messing with FTP (you're sending the credentials in plaintext even if you're using cURL, unless you're using FTPS).

With regards,
Liu Shan Shui
http://lx.sg/
"Life would be much easier if I had the source code." - Anonymous




____________________________

Thanks Liu Shan Shui for verifying what I suspected...

I was "assuming" cURL with just FTP access was encrypting the data transit automatically, no need for FTPS or .pem files, or other "handshake" files needed.  I guess I was wrong...

Seems like that would be the next industry standard if someone wrote a lib that "encased" a username:password along transit over HTTP using a simple call... without all the HTTPS, FTPS, needing static IP, etc... etc... hassles...

I ended up going HTTPS, with .htaccess username:password "handshake", then I just used the good old fopen, fwrite, and fclose technique.

Consider this thread SOLVED!

Thanks for everyone's input and ideas....

SysAdm











_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Gmane