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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving files between servers w/ perl??

Status
Not open for further replies.

scott203

Programmer
Jul 5, 2001
9
0
0
US
Is there a way that a perl script can download a file from a remote URL to a local directory? Like say, how can I copy " to the local "file.txt"?
 
LWP::Simple will do it. Do a search of this forum (on 'LWP') for example use (goBoating has written and rewritten dozens of examples that i can remember).

good luck "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Ok, that works, thanks... BUT, the server that i am downloading from incorrectly reports the length of the file. It reports it as about 3 megs when the file is actually about twice that long. I am using getstore($url, $localfile) from the LWP::simple module and it only gets the first 3 megs of the file. So I need to know how to use more robust methods of getting the file so that I am not limited to how the server reports the length. maybe use LWP::UserAgent ?
 
Oh, and I forgot to mention that I figured all this out because when I try to dl the file to my pc using IE, it first reports that the length is 3.37 mb, but downloads past that to ~7mb. and the size of the file on my server (using getstore()) is 3455kb(=3.37mb).

thanks, any help is appreciated
 
no professional answer here. just an idea to make it work.

# system ("/usr/ucb/finger $form_user");

in your case
# system ("wget $remotefile $localfile");

 
Ivennard, could you explain that a bit? Im not sure how to use that nor am i familiar with the system function...
 
maybe i should have asked whether you using Unix or Win32.

the system call just uses one of the programs on your machine. you can gamble that it is not portable to another machine. here would be an easy example:

#!/usr/bin/perl
system ("ls");
system ("pwd");

these will show the files in the directory (ls) and print the working directory (pwd).

the "wget" call i mentioned before is a unix program that will download web related files without a browser.
does this help?

 
when i run that code.... nothing happens. This is on a Unix machine. It seems i can put anything between the quotes as a parameter and nothing happens. When I try to
Code:
print system(...);
it returns 65280 usually but 512 when i put some crazy stuff in there.
 
I tried to locate the code in the lwp modules that actually retrieves the response from the server.. and see what makes it shut down too early... but it seemed to be very layered and hard to pin down. Any ideas???
 
it really doesnt work? ouch. sorry, not much help than.
its not something like your perl being located in a different spot or something is it?

i did a copy from the sample above and pasted it into a blank perl file. (test.pl) then chmod 755 test.pl
then i ran it.
./test.pl (from another machine)

here are the results


File test.pl saved.
[lvennard@mrtg lvennard]$ chmod 755 test.pl
[lvennard@mrtg lvennard]$ ./test.pl
14all.txt~ Ws070901.fixed.log fixbin.pl fixweb.pl~ test.pl
15all.cgi Ws070901.fixed.zip fixbin.pl~ routers-v1.26 tmp
Desktop Ws070901.log fixweb.pl sample.log vs.zip
/home/lvennard
[lvennard@mrtg lvennard]$


could you try it again?
different version of perl maybe?
 
I think the problem with that is that i dont have access to the command line. Im trying to run the script by entering its URL in a browser... And I dont know where system() prints its output to, whether it would only be visible on the command line or if it would print to a web page. But then when I tried the wget function, no file turned up in the directory I was trying to download to even when I used the full path. I have perl version 5.003
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top