Moving files between hosts 
Author Message
 Moving files between hosts

Scenario:  I am trying to improve the website of a university department and
to tie more pages to databases, but support at the university is _very
limited_.  In development (at least), I have been getting around these
limitations by using my own private ISP account.  I am hoping that, once
everything is up and running, I can show that it works and perhaps persuade
the Powers That Be to install some software to enable me to port everything
to a university host.  I don't mind donating space on my ISP account for
now.

University Host:

-- Microsoft OSs (mostly NT4).
-- Netscape server.
-- Server goes down practically once a day --
  don't know if that's the OS's fault or the
  server's or just the administrator's.
-- Full access to department Web files.
-- No permission to install anything.
-- PHP, but not configured fully (whether by intention or not),
  e.g., no session variables.
-- No basic authentication.
-- No MySQL.
-- Support for FileMaker DB, which I looked into, but
  strikes me as a big waste of time and money --
  another {*filter*}ion to proprietary software, with
  it's own markup language, blah blah blah.
-- Perl, but I don't think DBI.
-- VERY unresponsive administration.

Private ISP:

-- Up-to-date PHP, fully implemented
  (except for a weird GD bug).
-- MySQL 3.23.
-- Up-to-date Lynx.
-- Up-to-date Perl, with DBI, in case I need it.
-- FreeBSD platform :-) .
-- Somewhat subject to DOS attacks, but
  still down less frequently than univ. host.
-- Responsive administrator, usually willing to install
  new components or updates at my request.
-- The administrator's trust -- full access to databases within
  MySQL environment, though not to database files
  from shell.  (That's probably a good thing, really.)

Current Status:  So far, I have implemented a database with the contact
information for faculty, staff, and administration.  At first, I had the
PHPs on the university host requesting the data from MySQL on my ISP's host.
This worked, though I thought it was a touch slow.  I had made entry and
revision forms in PHP, also on the university host, with secret URLs, but no
login procedure, because I had neither session variables nor basic
authentication available.  One day, my ISP had to bring the host down for a
whole day for a major hardware upgrade, so I made HTML copies of the output
of the three directory pages (faculty, staff, administration) and posted
those instead, on the university host.  These, naturally, display a bit
faster, and they would only go down if the whole university server goes
down, so there's no risk of the user opening a mysteriously empty page.  I
made the HTML copies the brute way, by copying the source code from my
browser's source view and then shipping those files by FTP to the university
server.  Also, I've moved the entry forms to my ISP, where I could put them
under more secure password protection.  Since then, I've just moved all the
PHP over to my ISP and have kept making these HTML copies and shipping them
to the university host.  This is obviously not ideal.

Plan:  For now, leave the PHP and databases on my ISP's host and the HTML
output on the university host, but automate the process of outputting the
files and posting them.  On the ISP side, I can do this fairly easily, with
a shell script that basically does this:
lynx -source http://www.*-*-*.com/ ; localdir/index.html

The entry form can activates the script to create the HTML output copy and
then changes location to a PHP residing on the university host that would
GET the HTML file from the ISP host by FTP and then changes location to
display the HTML page on the university host, which is the finished page.

Questions:
1.  To activate the script, should I use system()?
2.  How do I write the PHP on the university side to get the file from the
ISP host and then store it locally?

I posted all this background in case people have other additional
suggestions or warnings or whatever.   Thanks!

Amittai Aviram



Mon, 30 May 2005 00:23:08 GMT  
 Moving files between hosts

Quote:

> Plan:  For now, leave the PHP and databases on my ISP's host and the HTML
> output on the university host, but automate the process of outputting the
> files and posting them.  On the ISP side, I can do this fairly easily, with
> a shell script that basically does this:
> lynx -source http://www.mydomain.com/mypages/index.php > localdir/index.html

> The entry form can activates the script to create the HTML output copy and
> then changes location to a PHP residing on the university host that would
> GET the HTML file from the ISP host by FTP and then changes location to
> display the HTML page on the university host, which is the finished page.

> Questions:
> 1.  To activate the script, should I use system()?
> 2.  How do I write the PHP on the university side to get the file from the
> ISP host and then store it locally?

> I posted all this background in case people have other additional
> suggestions or warnings or whatever.   Thanks!

I have the feeling you will receive several good
suggestions on how this could be done.

Mine would be like so:

    1] Build the pages in PHP
        Have a submit button on a webform
        which activates a script on your server.
    2] FTP them
        Use PHP FTP functions to connect to
        your uni's server and upload the files.

You should be able to keep all of the logic inside PHP.

If you are building the pages dynamically in PHP,
you can capture the output using output buffering
instead of using lynx.

e.g.)
    ob_start();
    // output page contents
    $contents = ob_get_contents();

    ob_end_clean(); // this stops output

You could do the above conditionally
i.e.) if($ran_as_batch) { // do output buffering }

Alternatively, ouput could be captured using
fopen('http://yourserver.com/yourfile');
This would require no edits to your current files.

If your ISP has compiled PHP with FTP enabled,
you could save the files contents to a temp directory,
then loop through the directory uploading files.

When I think of applications which work in this way,
I always think of moveable type as a good reference.
It is written in Perl, but its functionality could
be duplicated in PHP.  This would be similar to
'Rebuild Site' inside that application.

--
regards,
reggie.



Mon, 30 May 2005 05:00:46 GMT  
 Moving files between hosts

Quote:

> 1.  To activate the script, should I use system()?

Or exec(), if you don't want to see the output.

Quote:
> 2.  How do I write the PHP on the university side to get
>     the file from the ISP host and then store it locally?

Something like this:

$content = file ("http://remotehost.com/script.php");
if (!$content) {
  echo "Can't read the output of the remote script...";

Quote:
} else {

  $fp = fopen ("localfile.htm", "w");
  foreach ($content as $line) {
    fputs ($fp, $line);
  }
  fclose ($fp);
  echo "File localfile.htm created successfully...";

Quote:
}

Cheers,
NC


Mon, 30 May 2005 10:04:06 GMT  
 Moving files between hosts
[Posted to group.  Courtesy copy to poster.]


Quote:
> If you are building the pages dynamically in PHP,
> you can capture the output using output buffering
> instead of using lynx.

> e.g.)
>     ob_start();
>     // output page contents
>     $contents = ob_get_contents();

>     ob_end_clean(); // this stops output

> You could do the above conditionally
> i.e.) if($ran_as_batch) { // do output buffering }

> Alternatively, ouput could be captured using
> fopen('http://yourserver.com/yourfile');
> This would require no edits to your current files.

Thanks, Reggie!  I had been assuming that such methods would wind up getting
me the entire HTTPD output, HTTP headers and all, which I didn't want, but
after reading your posting I went to the manual and, lo and behold, fopen()
will invoke an appropriate HTTP wrapper if PHP has the default
configuration.  I just tested this, and -- after some fiddling -- got it to
work!  But there was one strange thing.  I ran into predictable permissions
issues, because, of course, Apache is writing as "nobody."  So fine, I
thought, I created a subdirectory to which to write, called "write," and
gave it rwxrw-rw- (766) permissions.  To my surprise and dismay, however,
this did not work.  I only got the thing to write if I granted full 777
permissions.  Why is this?  Why would Apache need _execution_ permission to
write a file on this directory?

Thanks again!

Amittai



Mon, 30 May 2005 10:32:18 GMT  
 Moving files between hosts

Quote:

> a shell script that basically does this:
> lynx -source http://www.*-*-*.com/ ; localdir/index.html

Why not set up a cron job on the University servers with that command
in it?? set it up to run every half hour or so. put a message on the
update form that it may take up to half an hour (or whatever update
period) for their details to be changed.

oops ... i see you have to use WinNT on the uni servers. {*filter*}. try
the 'at' command:

Quote:
> C:\Documents and Settings\Will>at /?
> The AT command schedules commands and programs to run on a computer at
> a specified time and date. The Schedule service must be running to use
> the AT command.

> AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
> AT [\\computername] time [/INTERACTIVE]
>     [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

> \\computername     Specifies a remote computer. Commands are scheduled on the
>                    local computer if this parameter is omitted.
> id                 Is an identification number assigned to a scheduled
>                    command.
> /delete            Cancels a scheduled command. If id is omitted, all the
>                    scheduled commands on the computer are canceled.
> /yes               Used with cancel all jobs command when no further
>                    confirmation is desired.
> time               Specifies the time when command is to run.
> /interactive       Allows the job to interact with the desktop of the user
>                    who is logged on at the time the job runs.
> /every:date[,...]  Runs the command on each specified day(s) of the week or
>                    month. If date is omitted, the current day of the month
>                    is assumed.
> /next:date[,...]   Runs the specified command on the next occurrence of the
>                    day (for example, next Thursday).  If date is omitted, the
>                    current day of the month is assumed.
> "command"          Is the Windows NT command, or batch program to be run.

> C:\Documents and Settings\Will>

hope that helps

Cheers,
Will M
--
Registered Linux User #273744
<www.volutin.net -- everything irrelevant>
now playing :: bare{*filter*} ladies - one week



Mon, 30 May 2005 11:18:22 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Host Data Moved to PC/LAN

2. PHP Web Hosting Shop - Find Your Web Hosting

3. Python-Hosting.com: new Hosting Provider specialized in Python

4. nawk: hosts.txt makes too many open files

5. TCP/IP And Host File

6. ANS TC Magnet for Host and File Struct.

7. ANS TC Magnet for Host and File Struct.

8. problem with file open on local host

9. expect telnet script, connect to hosts in a text file

10. How to post HTML file created by Tcl script to Navigator running om the same host

11. Move up/Move down buttons

12. Group level move vs sub-group level move.

 

 
Powered by phpBB® Forum Software