Copying files without a ftp cliant

chrishirst

Well-Known Member
Staff member
You can't.

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

chrishirst

Well-Known Member
Staff member
I've copied them from one web page to another.

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.

I can't copy them from one web page to my computer

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.
 

Glenn

Member
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.
 

chrishirst

Well-Known Member
Staff member
At one time I had something that copied a bunch of pictures from a web page to the one I uploaded the code to.

Still not using PHP to 'push' files, that is PHP pulling files from one server to another.
 

Glenn

Member
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.
 

chrishirst

Well-Known Member
Staff member
You still need to define what you mean by a 'web page' as a 'web page' is just text.
 

chrishirst

Well-Known Member
Staff member
Oh and, PHP might well be creating the text for the document, but it is NOT copying any files to anywhere.

I do not remember how I did that though

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

AND still not done with PHP.
 

Glenn

Member
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.
 

chrishirst

Well-Known Member
Staff member
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/
 

chrishirst

Well-Known Member
Staff member
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.
 

Glenn

Member
It would work similar to how pinterest copies images from one site to theirs. Except I need mp3 files.
 

chrishirst

Well-Known Member
Staff member
It would work similar to how pinterest copies images from one site to theirs. Except I need mp3 files.

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
 

chrishirst

Well-Known Member
Staff member
That is what this;
How can I write a php file to download an entire folder onto my computer from my website?
seems to suggest.

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

Glenn

Member
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.
 

chrishirst

Well-Known Member
Staff member
Is there a way to create a file that opens them all and I can do a "save page"?
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.
 
Top