Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open file on remote server?

Status
Not open for further replies.

mwcart

MIS
Sep 26, 2000
9
US
I am trying to write a (PERL) program that opens a file on a remote server and writes it to a file on a server where the program exist. I have the program working fine as long as the file opened for reading and the file for input are on the same server. I can't get the program to work if I try to open the file while it is on a different server. Can anyone tell me how I can open a file on a different(remote)server and write to a file on the server where the program exist.

Thanks in advance

mwcart [sig][/sig]
 
Russ

Thanks for the quick response

No I haven't tried that - not sure how to programmatically, but if I could get the program to pull the file down I think that would work. What I am trying to accomplish is this. I am going to be hosting sites that contain a flat file database. On each site I want to have a program that reads this database periodically(cron job) and deletes a special category. I also want the program to open a flat file on another server, read the contents and print to the original database file. This way I can update one file and let the program on each site update that sites database when the program is called by cron. Does this help any?

I have every thing in the program working except getting it to open the read file when it is on a different server.

Thanks again

mwcart [sig][/sig]
 
Hi, a little confused on what you're saying here.

>Thanks for the quick response
>
>No I haven't tried that - not sure how to programmatically, but if I could get the program to >pull the file down I think that would work. What I am trying to accomplish is this.

>I am going to be hosting sites that contain a flat file database.

Ok...

>On each site I want to have a program that reads this database periodically(cron job)

Ok, each site is a different machine and each machine will have a cron job that runs this
program right?

>and deletes a special category.

Do you mean moves a set of records that fit a certain criteria and then rewrites the
flat file?

>I also want the program to open a flat file on another server

Ok, so the same program also contacts another server and gets the flat file there...

>read the contents and print to the original database file.

What is the original database file? Do you mean the flat file that exists on the same
server that the program is running on? Do you want to add the records from the remote flat
file to the local file?

>This way I can update one file and let the program on each site update that sites database when >the program is called by cron. Does this help any?

Is the purpose to keep the flat files on each site the same?

>I have every thing in the program working except getting it to open the read file when it is on >a different server.

Try downloading the Net::FTP module. This will prevent you from having to do any sockets programming. The module has very easy to use FTP functionality. Of course, this means that you're going to have to set up an FTP daemon on each site. Another possibility, is using HTTP to get at the flat files. This, of course, presupposes that the flat files are somewhere in the document root of your web server.

Regards, [sig]<p>Russ<br><a href=mailto:bobbitts@hotmail.com>bobbitts@hotmail.com</a><br><a href= is in</a><br>[/sig]
 
...'just thinking out loud.....(or is that, just thinking into a browser input box...????)

If you used HTTP, you could write a simple CGI on each remote machine to read and print desired flat file when called. That CGI could use a password or do some checking to make sure the call is coming from a specific source. [sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
Russ

You understand me correctly. I'm still learning perl and just don't know how to impliment the Net::FTP module or connect using HTTP (program wise). Do you know where I can find tutorials or examples on how this is done. I have two large perl books but they don't show an example of these connection methods.

Thanks for all of your help.

goBoating > Thanks for your help too. If you know where I can find an example of how to do this I think I can make it work.

Thanks again

mwcart
[sig][/sig]
 
Good Morning mwcart,
My first suggestion is to follow Russ's suggestion and go with the module. It may take you a little work to figure out how to get the module (CPAN or ActiveState) and install it, and then how to use it. But, once you have those things figured out, you will use them repeatedly. I have not thought through all of the pros and cons of the HTTP/CGI approach.....but......

On each remote server, put something named 'getReport.cgi' that looks like.....
Code:
#!/usr/local/bin/perl -w
use CGI;
$q = new CGI;
print $q->header;
print $q->start_html;

# open/read file to report
open(IPF,&quot;<someFileHere&quot;) or &showError('Oops');
while (<IPF>) { print; }
close IPF;

print $q->end_html;

On the local server that is polling all of the remote servers for their files......
Code:
#!/usr/local/bin/perl -w
use LWP::Simple;
@remoteServers = (
    '[URL unfurl="true"]http://www.server1.com/cgi-bin/getReport.cgi',[/URL]
    '[URL unfurl="true"]http://www.server2.com/cgi-bin/getReport.cgi',[/URL]
    '[URL unfurl="true"]http://www.server3.com/cgi-bin/getReport.cgi');[/URL]

foreach $server (@remoteServers)
    {
    $file_from_server = '';
    $file_from_server = get($server);
    # you now have the content printed by the remote web server.
    # open another file and print to that or do other stuff with the 
    # content from the remote server
    }
[sig]<p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top