Copying files without a ftp cliant

Discussion in 'Web Design' started by Glenn, Oct 18, 2016.

to remove all ads.
  1. Glenn

    Glenn Member

    Messages:
    202
    How can I write a php file to download an entire folder onto my computer from my website?
     
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    You can't.

    A PHP script only runs when requested and cannot 'push' files to a remote computer.
     
  3. Glenn

    Glenn Member

    Messages:
    202
    I've copied them from one web page to another. I can't copy them from one web page to my computer?
     
  4. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    Explain what you mean by "from one web page to another". because generally a 'web page' is a text document comprising some form of 'mark-up code' and does not hold 'files', it may however display 'links' to where the file resource is located, as that is what 'URL' means.

    Assuming in this instance "web page" means 'URL', this is not using PHP to transfer the files. PHP merely displays the location of the resource so the browser can initiate a HTTP download.

    PHP runs on a server and has absolutely no access to save files on your computer. It may appear to you that PHP is transferring files, but that is very, very far from what is actually happening.
     
  5. Glenn

    Glenn Member

    Messages:
    202
    At one time I had something that copied a bunch of pictures from a web page to the one I uploaded the code to. I'm sure I still have it somewhere but I do not remember where.
     
  6. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    Still not using PHP to 'push' files, that is PHP pulling files from one server to another.
     
  7. Glenn

    Glenn Member

    Messages:
    202
    I have been able to copy images fro m one web page to another by reading the image files. I do not remember how I did that though.
     
  8. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    You still need to define what you mean by a 'web page' as a 'web page' is just text.
     
  9. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    Oh and, PHP might well be creating the text for the document, but it is NOT copying any files to anywhere.

    Probably by using a right click -> Save image as ...

    AND still not done with PHP.
     
  10. Glenn

    Glenn Member

    Messages:
    202
    I was able to write some code that copied all images from one web page to the page the code was ran from. I have .mp3 files that I want to do the same thing to.
     
  11. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    Still not sure what you mean by 'web page', so I will continue assuming that it is actually a URL, as a 'web page' is what you are reading this reply from.

    So. Yes, you CAN copy files from URL 'A' to to remote location 'B' where the php script is run from, using curl(), or wget() for binary files, or fgets(), fread() for text files, but you cannot run a script on machine 'A' and have it put the files on remote location 'B', which is what you are wanting to do.

    The script HAS to run on the location that you want to copy the files to.

    Assuming you run M$ Windows just install [url-"https://www.cygwin.com/"]CygWin[/url] and select the 'wget' component during setup, then use that to grab the files in a cygwin command prompt.

    Just 'cd' to the folder you want the file(s) in and use

    Code:
    wget http://domain.tld/folder/filename.ext
    to download an entire folder;

    Code:
     wget ‐‐directory-prefix=folder/subfolder domain.tld
    If you have a list of file URLs

    Code:
    wget ‐‐input list-of-file-urls.txt
    
    More info on wget can be found at http://www.labnol.org/software/wget-command-examples/28750/
     
  12. Dewlance

    Dewlance New Member

    Messages:
    15
    SCP, rsync is a alternative which can help you to copy file or use "cp" command (without quota)
     
  13. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    SCP and rsync both require SSH (shell) access to the server, so given that the TS apparently does not even have FTP access, it is reasonable to assume that 'shell' is also out of the question.
     
  14. Glenn

    Glenn Member

    Messages:
    202
    It would work similar to how pinterest copies images from one site to theirs. Except I need mp3 files.
     
  15. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    Again, this is a pull process not a push process, there are many, many ways you can pull files from point 'A' to point 'B', but you cannot 'push' files from point 'A' to point 'B', with point 'A' being the remote server and point 'B' being your local machine.

    Here is another way using wget.

    If you run a Linux OS just use wget to pull the files to your machine.
    If you run M$ Windows install wget for Windows.
    For MAC OS wget for MAC

    But you cannot use PHP on the server to push the files to your machine. It's NOT going to happen. It cannot happen
     
  16. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    And here's another Windows possibility to pull files from a website.

    [url="]https://www.httrack.com/]HTTrack[/url]

    Also available for MAC or Linux.
     
  17. Glenn

    Glenn Member

    Messages:
    202
    I'm not asking to push them.
     
  18. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    That is what this;
    seems to suggest.

    Now, if that is not the case and you meant something different, please explain further.
     
  19. Glenn

    Glenn Member

    Messages:
    202
    I understand what you mean now by pushing. Is there a way to create a file that opens them all and I can do a "save page"? I've tried doing that to no success.
     
  20. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,662
    Certainly there is, enable 'directory browsing' for the folder(s) and remove any 'index page' from that location is the simplest, but may not allow a browser "Save as" to download all files, you will need to test that for your server.
    And if you want the listing to look 'pretty' https://css-tricks.com/snippets/php/display-styled-directory-contents/

    Other than that you need to write a script that indexes the folder(s) and creates a list of URLs.

    such as this one does.
     

Share This Page