HTTP-404 has asked for the wisdom of the Perl Monks concerning the following question:

i have made this perl app to automate updates of my sites but some how it doesn't want t upload files my code is here
#!/usr/bin/perl use Net::FTP; $listfile="upload.lst"; open (FILE,"$listfile") or die "Can't open $listfile: $!"; @arr=<FILE>; my $i=0; foreach (@arr){ ($host[$i],$user[$i],$pass[$i],$rdest[$i],$ldest[$i],$file[$i])=spl +it(":",$arr[$i]); print "$i. Connecting..."; $ftp = Net::FTP->new($host[$i]) or warn "Can't Connect to $host[$i +] account $user[$i]\n" and next; print "$user[$i] Connected..."; $ftp->login("$user[$i]","$pass[$i]")or die "Can't Login to $ho +st[$i] account $user[$i]\n" and next; print "Logging in..."; $cwd="$rdest[$i]"; $ftp->cwd($cwd) or die "Can't cwd to $host[$i] account $user[$i]\n +" and next; print "Changing dir to /$rdest[$i]..."; $remote="$rdest"."/"."$fele[$i]"; #$local="$ldest[$i]"."/"."$file[$i]"; $local=$file[$i]; $pwd=$ftp->pwd(); print "Current dir $pwd..."; $ftp->put($local) or die "Can't Upload to $host[$i] account $u +ser[$i]\n" and next; print "Uploaded file $ldest[$i]/$file[$i]\n"; $ftp->quit; $i++; }
Perl always reports error: Bad Remote file name

Replies are listed 'Best First'.
Re: Multiple FTP uploader
by idnopheq (Chaplain) on May 05, 2001 at 16:15 UTC
    Should line 26 read $remote="$rdest"."/"."$file[$i]";?

    Also, if you turn on warnings ( -w ) and use the strict pragma ( use strict; ). Some of these plroblems will jump out at you. One can even wield the prolix ( use diagnostics; ) ...

    HTH
    --
    idnopheq
    Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.

(ar0n) Re: Multiple FTP uploader
by ar0n (Priest) on May 05, 2001 at 16:15 UTC
    Could it be because you have
    $remote="$rdest"."/"."$fele[$i]";
    instead of
    $remote="$rdest"."/"."$file[$i]";


    ar0n ]

      thnx for reply no the problem was that file is stored like this data:data1:data2 so if i extract the data last element will contaoin new line char so all ihad to do is to chomp that last element
      #!/usr/bin/perl use Net::FTP; $listfile="upload.lst"; open (FILE,"$listfile") or die "Can't open $listfile: $!"; @arr=<FILE>; my $i=0; foreach (@arr){ ($host[$i],$user[$i],$pass[$i],$rdest[$i],$ldest[$i],$file[$i])=spl +it(":",$arr[$i]); chomp($file[$i]); print "$i. Connecting..."; $ftp = Net::FTP->new($host[$i]) or warn "Can't Connect to $host[$i +] account $user[$i]\n" and next; print "$user[$i] Connected..."; $ftp->login("$user[$i]","$pass[$i]")or die "Can't Login to $ho +st[$i] account $user[$i]\n" and next; print "Logging in..."; #$cwd="$rdest[$i]"; #$ftp->cwd($cwd) or die "Can't cwd to $host[$i] account $user[$i]\ +n" and next; #print "Changing dir to /$rdest[$i]..."; $remote="$rdest[$i]"."/"."$file[$i]"; $local="$ldest[$i]"."/"."$file[$i]"; #$local=$file[$i]; $pwd=$ftp->pwd(); print "Current dir $pwd..."; $ftp->put($local,$remote) or die "Can't Upload to $host[$i] ac +count $user[$i]\n" and next; print "Uploaded file $ldest[$i]/$file[$i]\n"; $ftp->quit; $i++; }
      final code if some is intrested
Re: Multiple FTP uploader
by zigster (Hermit) on May 05, 2001 at 16:45 UTC
    To suggest a non perl solution, in the greatest tradition of why re-invent any round objects. You may want to take a look at the unix util rdist. Quote from rdist(1) below. Althought it does not solve your problem directly it may be of general interest.

    Rdist is a program to maintain identical copies of files over multiple hosts. It preserves the owner, group, mode, and mtime of files if possible and can update programs that are executing. Rdist reads commands from distfile to direct the updating of files and/or directories. If distfile is `-', the standard input is used. If no -f option is present, the program looks first for `distfile', then `Dist- file' to use as the input. If no names are specified on the command line, rdist will update all of the files and direc- tories listed in distfile. Otherwise, the argument is taken to be the name of a file to be updated or the label of a command to execute. If label and file names conflict, it is assumed to be a label. These may be used together to update specific files using specific commands.


    --

    Zigster
      Depending on your needs, I definitely prefer the reinvented wheel called rsync. Just because something has been invented doesn't mean that it cannot be usefully redone. It just means that you should think twice before you do it and have a reason. But wheels have been reinvented a few times over the last few thousand years, and on the whole I prefer the ones that we have today... :-)

      ObRandomObservation: Take a look. While you are not supposed to reinvent wheels, hubcaps seem to be a different story...

        COo ++, rdist is good but if there is better always worth a look. I will dl it at once.
        --

        Zigster