Using File::Copy and Sockets to copy public files from http addresses 
Author Message
 Using File::Copy and Sockets to copy public files from http addresses

My company has a relationship with a partner where they post files on
their website for us to download.  I am writing a perl script to
automate the process.

I begin by using the File::Copy module to provide the basic Copy
function.  However, since the souce file is not in my Host's
directory, I believe I need to set up a Socket to provide connectivity
to the partner server where the file lives and that is where I need
help.

The code fragment I am working with is as follows but it does not work
for me.  I would appreciate some help.

   use Socket;
   $domain = PF_INET;
   $type   = SOCK_STREAM;
   $proto  = getprotobyname('tcp');
   socket(PARTNER, $domain, $type, $proto) or die "socket: $!\n";
   $port     = 0;
   $sockaddr = sockaddr_in($port, INADDR_ANY);
   bind(PARTNER, $sockaddr) or die "bind: $!\n";
   $host     = ' http://www.*-*-*.com/ $ProductID.txt';
   $port     = getservbyname('http', 'tcp');
   $ip_addr  = inet_aton($host) or die "inet_aton: $!\n";
   $sockaddr = sockaddr_in($port, $ip_addr);
   connect(PARTNER, $sockaddr) or die "connect: $!\n";

   use File::Copy;
   copy PARTNER, "../www/mono_mp3/$ProductID.mp3";

Thanks for you time and help,

Jeff



Wed, 02 Nov 2005 03:37:39 GMT  
 Using File::Copy and Sockets to copy public files from http addresses


Quote:
> My company has a relationship with a partner where they post files on
> their website for us to download.  I am writing a perl script to
> automate the process.

You might want to take a look at the lwp modules on CPAN

Mothra



Wed, 02 Nov 2005 04:10:14 GMT  
 Using File::Copy and Sockets to copy public files from http addresses

Quote:



> > My company has a relationship with a partner where they post files on
> > their website for us to download.  I am writing a perl script to
> > automate the process.

> You might want to take a look at the lwp modules on CPAN

> Mothra

Mothra,

I appreciate the response.  Although I have used LWP to POST to
various web pages from my Perl scripts, my review of the modules
contained in LWP did not lead me to an obvious answer on how to copy
public files located on a distant server.

Would you be so kind as to guide me to the module or modules you think
would help me?

Thanks,

Jeff



Wed, 02 Nov 2005 12:19:41 GMT  
 Using File::Copy and Sockets to copy public files from http addresses
Hi Jeff,

Quote:
> Mothra,

> I appreciate the response.  Although I have used LWP to POST to
> various web pages from my Perl scripts, my review of the modules
> contained in LWP did not lead me to an obvious answer on how to copy
> public files located on a distant server.

Here is part of a script I use to download files from the web.

use HTTP::Request::Common;
use LWP::UserAgent;
use strict;
use warnings;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $path_info='f:\areacode';

my $logfile ='c:\temp\logfile.txt';

esutlzd.zip wnutlzd.zip wputlzd.zip wsutlzd.zip);

my $temp_file ="$path_info/out.txt";
unlink $temp_file;
############################################################################
# get the files from the web
############################################################################

my $ua = LWP::UserAgent->new;

$ua->agent('Mozilla/4.73');
open (LOG,">$logfile") or die "Can't open $logfile:$!\n";


my $request = HTTP::Request->new(GET =>
                "http://www.nanpa.com/nanp1/$filename");

my $res = $ua->request($request,"$path_info/$filename");

  if ($res->is_success) {
     print LOG "downloaded $filename completed\n";
     my $zipfile = Archive::Zip->new("$path_info/$filename");

     die "Could not extract $names[0] from $filename: $!" if
$zipfile->extractMember("$names[0]", "$path_info/$names[0]") != AZ_OK;
     unlink ("$path_info/$filename");
  }
  else {
     print LOG $res->status_line, "\n";
     exit (0);
  }

Quote:
}

close LOG;

Quote:

> Would you be so kind as to guide me to the module or modules you think
> would help me?

> Thanks,

I hope this helps.

Mothra



Fri, 04 Nov 2005 21:17:34 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Warning using copy from File::Copy

2. File::Copy, copying files problem.

3. unwanted UNIX file permissions after using File::Copy::syscopy

4. Semantics of File::Copy::copy(,)

5. how to copy values from a file into a oracle-table using DBI

6. File::Copy from NT to Unix using UNC

7. How to copy files using system( ) in a Perl script

8. Using system( ) command to copy files

9. Using perl to copy JPG files

10. [Fwd: Using link to copy a file]

11. Error using File::Copy

12. Using system() to copy strange files

 

 
Powered by phpBB® Forum Software