Web Hosting Talk







View Full Version : transfer textfile contents


innova
03-04-2005, 04:04 PM
Hi,

I want to send the contents of a textfile from one machine to another. I was thinking a way to do this would be to get_file_contents, then serialize() them, and send the serialized bytes over the net to a socket server on the other side, where it would be unserialize(d).

I wanted to do something entirely in PHP, not using any external protocols. I think by using sockets it can be done.

What I want to know is.. are there any other approaches I should be considering? What alternatives are there?

Azavia
03-04-2005, 04:38 PM
If the remote machine has an FTP server, you can just transfer it over FTP via PHP.

error404
03-04-2005, 04:51 PM
Why serialize? Just open a socket, and either write a simple protocol, or just dump the data straight there. Serialization may cause issues if you end up with different versions of PHP on the servers, or if you later decide to write a client in another language.

You could use SOAP too...

innova
03-04-2005, 05:24 PM
Zapx,
If the remote machine has an FTP server, you can just transfer it over FTP via PHP.
As I mentioned, >>>I wanted to do something entirely in PHP, not using any external protocols.

error404,
either write a simple protocol, or just dump the data straight there.

Can you elaborate on this at all?

Are you saying I should (client side) just read the file into a variable, fsockopen, and fwrite() the $variable?

error404
03-04-2005, 06:45 PM
Originally posted by innova

Can you elaborate on this at all?

Are you saying I should (client side) just read the file into a variable, fsockopen, and fwrite() the $variable?

Essentially, yea. If you only ever need to transfer a text file or whatever, without any metadata, that's all you'd need to do. If you want like a filename or whatever too, then you could write a simple header protocol or some such, a la HTTP. Since the communication is only one-way, the code should be quite simple.