×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to open file on remote server?

How to open file on remote server?

How to open file on remote server?

(OP)
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

RE: How to open file on remote server?

How are you trying to do this? Have you tried FTP'ing the file from the remote server to your server?

Regards,

Russ
bobbitts@hotmail.com
Bobbitt is in

RE: How to open file on remote server?

(OP)
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

RE: How to open file on remote server?

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,

Russ
bobbitts@hotmail.com
Bobbitt is in

RE: How to open file on remote server?

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




keep the rudder amid ship and beware the odd typo

RE: How to open file on remote server?

(OP)
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

RE: How to open file on remote server?

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

#!/usr/local/bin/perl -w
use CGI;
$q = new CGI;
print $q->header;
print $q->start_html;

# open/read file to report
open(IPF,"<someFileHere") 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......

#!/usr/local/bin/perl -w
use LWP::Simple;
@remoteServers = (
    'http://www.server1.com/cgi-bin/getReport.cgi',
    'http://www.server2.com/cgi-bin/getReport.cgi',
    'http://www.server3.com/cgi-bin/getReport.cgi');

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
    }




keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close