1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is it possible...

Discussion in 'General Programming Chat' started by KennWort, Apr 20, 2008.

  1. KennWort

    KennWort Registered Member

    Joined:
    Apr 1, 2008
    Messages:
    68
    Likes Received:
    99
    Is there such thing, or could there be, a PHP-type script, that when executed on a webpage could download files from a site directly to a folder on your webhost?

    I don't even know how to query that one on a SE... :confused:
     
  2. artswerdstone

    artswerdstone Power Member

    Joined:
    Nov 24, 2007
    Messages:
    673
    Likes Received:
    764
    You may need eventually a script like that on the page hxxp://lunamoth.naool.com/fxp/phpfxp.php
     
  3. artswerdstone

    artswerdstone Power Member

    Joined:
    Nov 24, 2007
    Messages:
    673
    Likes Received:
    764

    However the author's site is down for a long time, but finally I could fetch a copy for you from a Russian software site (finally I will learn Russian, LOL).

    You just save the attachment or get it from the following link, as you like.

    hxxp://rapidshare.com/files/108896313/phpfxp_3.zip
     

    Attached Files:

  4. boomboomer

    boomboomer Executive VIP

    Joined:
    Feb 7, 2008
    Messages:
    705
    Likes Received:
    865
    If the transfer destination is always to a single webhost, you could write a simple PHP script that takes the file's URL as an input and then fetches the file using the 'wget url' command and then stores it to a secure folder.

    If this is what you want, and you need help, lemme know.
     
  5. snowtorious

    snowtorious Newbie

    Joined:
    Apr 9, 2008
    Messages:
    3
    Likes Received:
    0
    You can also use cURL. Check out this short tutorial: http://phpsense.com/php/php-curl-functions.html

    cURL can also use proxy servers, store cookies and login to remote sites, and simulate a real user by acting as a visitor using whatever browser and operating system you specify.
     
  6. KennWort

    KennWort Registered Member

    Joined:
    Apr 1, 2008
    Messages:
    68
    Likes Received:
    99
    Yes, please... I can't write anything but a DOS batch file, LOL

    This looks interesting, but where do you put the "from" and "to"?

    Thanks for the replies...
    (the ftp is not what I am looking for artswerdstone - ty for looking tho)
     
  7. artswerdstone

    artswerdstone Power Member

    Joined:
    Nov 24, 2007
    Messages:
    673
    Likes Received:
    764
    You're welcome KennWort. If you're going to explain a bit more in details the purpose of the script, maybe you will get something that fits better that purpose.

    You wrote you need a script that loads files from a site to a folder on your webhost.

    If fxp doesn't fit your needs, then curl may be the solution, if your host supports curl. You have to check your host's PHPinfo if it contains cURL support enabled.
    You may create with Notepad a file named phpinfo.txt with the following content:

    Code:
    <?php
    
    phpinfo();
    
    ?>
    Upload that file to your web folder, rename it to phpinfo.php, then run it by opening it in your web browser:

    http://yoursite.com/phpinfo.php

    Then read the results and check for the section "cURL".

    If you have "cURL enabled", then you can use a curl script as per following sample:


    Code:
    <?php
    /**
    * Initialize the cURL session
    */
    $ch = curl_init();
    /**
    * Set the URL of the page or file to download.
    */
    curl_setopt($ch, CURLOPT_URL,
    'http://yoursourcesite.com/yoursourcefile.pdf');
    /**
    * Create a new file
    */
    $fp = [URL="http://www.php.net/fopen"]fopen[/URL]('yourtargetfile.pdf', 'w');
    /**
    * Ask cURL to write the contents to a file
    */
    curl_setopt($ch, CURLOPT_FILE, $fp);
    /**
    * Execute the cURL session
    */
    curl_exec ($ch);
    /**
    * Close cURL session and file
    */
    curl_close ($ch);
    [URL="http://www.php.net/fclose"]fclose[/URL]($fp);
    ?>  
         
    
    Replace "yoursourcesite.com/yoursourcefile.pdf" with whatever source file you want (this is your FROM statement).


    Then replace "yourtargetfile.pdf" to the name you desire (this is your TO file, that will be located in the same folder with your above curl script).

    Now make your file as per the above sample, name it "transfer.php" or any name you want, but with extension ".php". Upload it onto your website in your folder you want to transfer the file from your source.

    Run the script either manualy, by calling it from your browser (hxxp://yoursite.com/download/transfer.php), or automatically by creating a cronjob that will execute the transfer.php script regularly at a given time.


    It's not anything harder, then writing a DOS batch file, just go and do it. Success!
     
  8. KennWort

    KennWort Registered Member

    Joined:
    Apr 1, 2008
    Messages:
    68
    Likes Received:
    99
    Thanks artswerdstone,

    One more quick question...

    Is there some way to have the SOURCE, and DESTINATION as variables that I can input for different files?
    I'm thinking (and learning, I think, LOL) that this might be able to be done via the "post" or "get" form method?

    Oh, the reason for this "request"?
    Some of the "shares" on BHW are quite awesome, and I'm running into a storage issue... :juggle:
     
  9. artswerdstone

    artswerdstone Power Member

    Joined:
    Nov 24, 2007
    Messages:
    673
    Likes Received:
    764
    Thanks for sharing the reason of the request; now it's easier to understand what you would really like to have.

    Of course, you can define and use variables as you wish, and it is possible to make an interface with a form to input your actual settings or batch jobs.

    I am only afraid about you will need as next step an authentication feature and possibly a CAPTCHA dialog to be able to access some of the shares. As I am clearing up my backlogs, now I am a bit too busy (further I've entered into a couple of urgent projects that need quit a hard work and I sit watching computer screen until I get half blind and I type until I get half inch off of my fingers).

    Eventually you will be delighted to learn a little about how easy is PHP programming...
    You will find a reference to a great tutorial in the following post:

    http://www.blackhatworld.com/blackhat-seo/member-downloads/11428-php-know-all-manual.html#post101888

    I hope you will have fun.
     
    Last edited: Apr 22, 2008