l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Jul 01 16:27

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Another Perl Question: File::Find module not working as expected
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Another Perl Question: File::Find module not working as expected

The following script addresses the problem I had earlier of moving files
from a Windows computer to a Unix server when the directory structures are
different.  Within each subfolder on the Unix server there is a directory
called "messages".  For some reason, it seems that File::Find is not
traversing the directory tree properly and going into the messages folder
at all.

Any suggestions would be more than welcome.

#!/usr/local/bin/perl -w

# FILE:		vton.pl
# PURPOSE:	Retrieve current discussion board messages
#		from Vader and put them on Neo
# AUTHOR:	Richard Crawford (rcrawford@unexmail.ucdavis.edu)
# CREATED:	25 June 2003
# ===============================================================
# DATE          AUTHOR  EDIT
# 07/01/03	RC	Updated script to retrieve multiple files
# ===============================================================

use strict;
use File::Find;
use Net::FTP;

my $vaderIP = "xxx.xxx.xxx.xxx";

my $start_dir = shift or die "Usage: $0 <start_dir>\n";

unless (-d $start_dir) {
  die "Start files $start_dir is not a directory.\n";

# Connect to Vader
my $VaderConnect = Net::FTP->new($vaderIP) or die ("VTON: Can't connect to
Vader: $!\n");

$VaderConnect->login('Richard','password') or die ("VTON: Can't log in to
Vader: $!\n");

print "\nVTON: Successfully connected to Vader.\n\n";

# traverse directory tree and move files
find (\&move, $start_dir) or die ("Couldn't get to $File::Find::dir/$_:

# Disconnect from Vader

sub move { #subroutine to move files

  # Find out the IP address of the current computer
  my $interface="hme0";
  my $ifconfig="/usr/sbin/ifconfig";
  my @lines = qx|$ifconfig $interface| or die "Could not execute ifconfig:
  my $neoIP;
  foreach(@lines) {
    if (/inet ([\d.]+)/) {
      my $neoIP = $1;

  # Find the current directory
  my $neoDir = $File::Find::dir;

  # Move to the equivalent directory on Vader
  my $baseDir = $neoDir;
  $baseDir =~ s#/space/usr/jrun4/servers/default/cfusion/DLC/##g;
  my $vaderDir = "/HTTPHome/$baseDir";
  $vaderDir =~ s#/extras##g;


  # Get all the files on Vader in this directory

  my @VaderFiles = $VaderConnect->ls($vaderDir) or die ("Cannot get list
of files: $!\n");

  # Now get each item from Vader and process them
  my $currentFile;

  print ("Number of files in $vaderDir: $#VaderFiles\n"); # return;

  foreach $currentFile (@VaderFiles)

    $currentFile =~ s(^.*/)();

    return unless (
      ($currentFile =~ m/[0-9]+.html$/) or #message files
      ($currentFile =~ m/data.txt$/) or    #data.txt
      ($currentFile =~ m/wwwboard.html$/) #wwwboard.html

    print "\nCurrent File is $currentFile\n";

    # Get the file from Vader

    # Replace "action=wwwboard.pl" with direct path to wwwboard.pl
    # Create an absolute path to wwwboard.pl
    $neoDir =~ s#/space/usr/jrun4/servers/default/cfusion/##g;
    my $URL="http://$neoIP/$baseDir/wwwboard.pl";;
    $URL =~ s#/messages##g;
    my $VaderURL="$baseDir/wwwboard.pl";;
    $VaderURL =~ s#/messages##g;
    unless (open IN, $currentFile) {
      die "VTON: Can't open file $currentFile for reading: $!\n";
    unless (open OUT, "> fixedfile") {
      die "VTON: Can't open output file: $!\n";
    while (<IN>) {
      # Fix form action tags.
      # Fix style sheet call:
      if ($currentFile =~ m#[0-9]+.html$#) {
      print(OUT $currentFile) or die "VTON: Can't write to fixedfile: $!\n";
    close (IN);  close (OUT);

    chmod 0777, $currentFile;

    print "VTON: Copied and fixed $File::Find::dir/$currentFile\n";

Richard S. Crawford

AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford
MSN: underpope@hotmail.com

"It is only with the heart that we see rightly; what is essential is
invisible to the eye." --Antoine de Saint Exupéry

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.