|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
little problems with MPUT (ftp & perl script)
I am trying to upload all .csv files in c:\temp\
I am getting an error whenever i run the code: "can't get the object put from "c:\temp\*.csv" perhaps you forgot to load it. Is there a simple way to upload all files of a certain type to an ftp server? here is my code: Code:
use Net::FTP;
$ftp = Net::FTP->new("ftp.myserver.com");
$ftp->login("uesername","pass");
$ftp->cwd("/var/www/html/data/uploads/");
sub mput { my($ftp,$pattern) = @_;
foreach my $upload (glob($pattern)) { $ftp->put($upload) or warn $ftp->message; } }
&mput("c:\\temp\\*.csv");
$ftp->quit;
Thanks for the help |
|
#2
|
|||
|
|||
|
i changed it to this:
Code:
for (glob("c:\\temp\\*.csv")) {
$ftp->put($_);
}
and it works with no errors, i just don't get any files uploaded. Any hints or tips as to why the files aren't going? |
|
#3
|
|||
|
|||
|
Um... Your &mput takes 2 args, yes? In your call to mput() I count only one arg.
FWIW... Here is a Perl script I just cobbled together to do the opposite: download. I banged it together for my boss. Tomorrow I'll try to compile it with PAR or Perl2Exe for Win2K so he won't even have to install Perl. This is my actual script, with only the IP, user and passwd obfuscated. I just ran it. It works. If you change the 'get' to 'put' and build your list other than from 'ls' it shouldn't be hard at all to tweak. This is my first Net::FTP script, cobbled from another by somebody else. I am using 'get' and a 'foreach' on a list with matching...since there is no 'mget' in Net::FTP that I could find. Code:
use strict;
use warnings;
use Net::FTP;
my $host = "666.666.666.666";
my $user = "foo";
my $pw = "bar";
my $path = "outgoing/foobar";
if ( my $ftp = Net::FTP->new($host) ) {
print "Logging in to '$host' as user '$user'.\n";
$ftp->login($user,$pw) or die "Could not login";
$ftp->pasv();
print "Changing directory to '$path'\n";
$ftp->cwd($path) or die "could not cwd $path";
$ftp->ascii;
my @files = $ftp->ls;
print "Found these files: \n\t" .
join( "\n\t", @files ) .
".\n";
foreach my $file (@files) {
if ( $file =~ /.*progress|monitor|gui|station.*txt/ ) {
print "Downloading file: $file.\n";
$ftp->get($file) or print "Oops! Could not get $file\n";
}
}
$ftp->close(); }
else { print "Could not connect.\n"; }
print "All done.\n";
Last edited by aplonis : February 4th, 2004 at 07:13 PM. |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > little problems with MPUT (ftp & perl script) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|