SPUG: How do I fix myself up? [Desperately seeking HELP]

Keith Aaron keith at photoworks.com
Tue Jun 6 10:08:28 CDT 2000


Now I get a different error when I try to execute the Perl script:

	C:\WINNT\system32\cmd.exe /c ftpget.pl -p -C -d
"E:/source/filmworks/SFW.SYS/SFW.BP/PD.JOBLOGGER" "filmworks:"
	DEBUG OUTPUT:
	  User:   keitha
	  Server: filmworks
	  Rpath:  /source/filmworks/SFW.SYS/SFW.BP/PD.JOBLOGGER
	  Lpath:  E:/source/filmworks/SFW.SYS/SFW.BP/PD.JOBLOGGER
	  Create: 1

<<...>>

Net::FTP=GLOB(0x8d6f234)<<< 200 TYPE I ok.
Net::FTP=GLOB(0x8d6f234)>>> MKD /source/filmworks/SFW.SYS/SFW.BP/
Net::FTP=GLOB(0x8d6f234)<<< 550 /source/filmworks/SFW.SYS/SFW.BP/ Error 17:
File
 exists
Net::FTP=GLOB(0x8d6f234)>>> MKD /source
Net::FTP=GLOB(0x8d6f234)<<< 550 /source Error 17: File exists
Net::FTP=GLOB(0x8d6f234)>>> MKD /source/filmworks
Net::FTP=GLOB(0x8d6f234)<<< 550 /source/filmworks Error 17: File exists
Net::FTP=GLOB(0x8d6f234)>>> MKD /source/filmworks/SFW.SYS
Net::FTP=GLOB(0x8d6f234)<<< 550 /source/filmworks/SFW.SYS Error 17: File
exists
Net::FTP=GLOB(0x8d6f234)>>> MKD /source/filmworks/SFW.SYS/SFW.BP
Net::FTP=GLOB(0x8d6f234)<<< 550 /source/filmworks/SFW.SYS/SFW.BP Error 17:
File
exists
Net::FTP=GLOB(0x8d6f234)>>> MKD /source/filmworks/SFW.SYS/SFW.BP/
Net::FTP=GLOB(0x8d6f234)<<< 550 /source/filmworks/SFW.SYS/SFW.BP/ Error 17:
File
 exists
Net::FTP=GLOB(0x8d6f234)>>> PWD
Net::FTP=GLOB(0x8d6f234)<<< 257 "/home/keitha" is current directory.
Can't locate object method "cd" via package "Net::FTP" at
C:/Perl/site/lib/Net/F
TP.pm line 464.
Net::FTP=GLOB(0x8d6f234)>>> QUIT
Net::FTP=GLOB(0x8d6f234)<<< 221 Goodbye.
255 returned
Hit any key to close this window...

It must be failing on the line:
    if ($rpath)  {$ftp->cwd($rpath);}

... but I don't see why.  Are there more packages I need to install?  And
how do I find out what I need to install when something is missing?


-----Original Message-----
From: Keith Aaron 
Sent: Thursday, June 01, 2000 6:39 PM
To: 'AHands at unforgettable.com'
Subject: RE: SPUG: How do I fix myself up? [Desperately seeking HELP]

Here's the script (it ain't elegant, but it works on the old system):

#!/usr/bin/perl
# simple ftp client for use from vim or the command-line!
# type ftpget without arguments to find
#
# The file will be got/put from/to the path provided, but will be stored
# locally in the current directory as the base file name.
#
# The server will be looked up in the table %servers, which will define the
# logon for that server (otherwise, be anonymous)
#
# written by: Ron Aaron
# last update:  01/24/98 14:54:49
#
############################################################################
###
# 09-24-99 Keith W. Aaron
#   -Allow different source and target; distinguish between drive and
server:
#        ftpget -p      E:\src\fw\SFW.SYS\PROG server:[path]
#        ftpget -G server:\src\fw\SFW.SYS\PROG      C:[path]
#   -Add -G,-P to replace -L (localpath)
#   -Add -c,-C to cause creation of path (local or remote) if doesn't exist
############################################################################
###

use Net::FTP;

%servers = ( # change for each 'secure' server (i.e., not anonymous login)
             'filmworks'          => 'my_username:my_password',  
             );
$anon           = 'keith at photoworks.com';	# email address
$proxy          = '';          i		# change to your FTP proxy
(if you have one)
$default_server = 'filmworks';       	# what server to use by default

# ---- don't change these:
$debug     = 0;      # default: debug OFF
$ls        = 0;      # default: xfer, not ls
$force     = 0;      # default: don't force case (uc vs lc)
$tpath     = 0;      # default: target = 'file'; 1 => target = 'path/file'
$create    = 0;      # default: deposit in cwd ; 1 => create path if !exist

# 1) parse command line
while ($arg = shift) 
{
  if    ($arg eq '-p') {$put    =  1;}
  elsif ($arg eq '-P') {$put    =  1; $tpath  =  1;}
  elsif ($arg eq '-g') {$put    =  0;}
  elsif ($arg eq '-G') {$put    =  0; $tpath  =  1;}
  elsif ($arg eq '-s') {$stdout =  1;}
  elsif ($arg eq '-d') {$debug  =  1;}
  elsif ($arg eq '-D') {$debug  =  2;}
  elsif ($arg eq '-f') {$force  = -1;}
  elsif ($arg eq '-F') {$force  =  1;}
  elsif ($arg eq '-c') {$create =  1; $tpath  =  1;}
  elsif ($arg eq '-C') {$create =  1; $tpath  =  1;}
  elsif ($arg eq '-l')
  {
    $ls  = 1;
    $arg = shift;
    goto process;        # '-l' is assumed to be the last flag
  }
  elsif ($arg eq '-h' || $arg eq '-H') {goto help;}
  else
  {
process:
    $source = $arg;
    $target = shift;
    process_file($source, $target);
    ++$processed;
  }
}
help:
syntax() if !$processed;

############################################################################
###

sub syntax
{
  print <<EOF;

Usage:

ftpget -{g|G} [flags] [server:]source_file [drive:][target_file]
ftpget -{p|P} [flags] [drive:]source_file  [server:][target_file]
ftpget   -l   [flags] [server:][directory]

  -g  get file, write to lcd
  -G  get file, write to target_path (default=source_path), if it exists
  -p  put file, write to cwd
  -P  put file, write to target_path (default=source_path), if it exists
  -l  get sorted dir listing (ls)

flags:
  -c  create target_path if it doesn't exist (forces -G|-P)
  -C  create target_path if it doesn't exist (forces -G|-P)
  -d  print debug info while executing
  -D  print debug info only; don't do transfer
  -f  force target filename to lowercase
  -F  force target filename to uppercase
  -s  get/put to/from stdout/stdin
EOF
}

sub process_file
{
  (my $source = shift); (my $target = shift);
  (my $s_srvr, $t_srvr, $s_path, $t_path, $s_file, $t_file);
  (my $server, $drive, $ix, $lpath, $lfile, $rpath, $rfile);

  # fix backslashes in DOS pathnames
  $source =~ s/\\/\//g;
  $target =~ s/\\/\//g;

  # split $source = s_srvr:s_path/s_file
  $s_path = $source;
  $ix     = index $s_path, ':';
  if ($debug == 2) {print "  \$source=$source\n  ix':'  =$ix\n";}
  if ($ix    >= 0) {$s_srvr = substr $s_path, 0, $ix;
                    $s_path = substr $s_path, $ix+1;}
  if ($debug == 2) {print "  s_srvr =$s_srvr\n  s_path =$s_path\n";}
  $ix = rindex $s_path, '/';
  if ($debug == 2) {print "  s_path =$s_path\n  ix'/'  =$ix\n";}
  if ($ix    >= 0) {$s_file = substr $s_path, $ix+1;
                    $s_path = substr $s_path, 0, $ix+1;}
  if ($debug == 2) {print "  s_path =$s_path\n  s_file =$s_file\n";}

  # split $target = t_srvr:t_path/t_file
  $t_path = $target;
  $ix     = index $t_path, ':';
  if ($debug == 2) {print "  \$target=$target\n  ix':'  =$ix\n";}
  if ($ix    >= 0) {$t_srvr = substr $t_path, 0, $ix;
                    $t_path = substr $t_path, $ix+1;}
  if ($debug == 2) {print "  t_srvr =$t_srvr\n  t_path =$t_path\n";}
  $ix = rindex $t_path, '/';
  if ($debug == 2) {print "  t_path =$t_path\n  ix'/'  =$ix\n";}
  if ($ix    >= 0) {$t_file = substr $t_path, $ix+1;
                    $t_path = substr $t_path, 0, $ix+1;}
  if ($debug == 2) {print "  t_path =$t_path\n  t_file =$t_file\n";}
  if (!$t_file)    {$t_file = $s_file;}
  
  # force target filename to upper/lower?
  if ($force) {$t_file = ($force < 0) ? lc $t_file : uc $t_file;}
  
  # Server vs Drive
  if ($s_srvr) {
    if ($s_srvr =~ /\b[A-Za-z]\b/) {$drive  = $s_srvr . ':';}
    else                           {$server = $s_srvr      ;} }
  if ($t_srvr) {
    if ($t_srvr =~ /\b[A-Za-z]\b/) {$drive  = $t_srvr . ':';}
    else            {if (!$server) {$server = $t_srvr      ;} } }
  if ($debug == 2) {print "  drive  =$drive\n  server =$server\n";}

  if ($server eq 'common') {
    print "Which system? "; $server = <>; chomp $server; }

  # is the server in our list?
  if (defined($servers{$server}))
  {
    ($user, $pwd) = split ":", $servers{$server};
  }
  else
  {
    $server = $default_server;
    ($user, $pwd) = split ":", $servers{$server};
#   $user = 'anonymous';
#   $pwd  = $anon;
  }
 
  if ($put) {
    if (!$t_path) {$t_path =          $s_path;}
                   $s_path = $drive . $s_path;}
  else {if ($tpath) {
    if (!$t_path) {$t_path = $drive . $s_path;}
    else          {$t_path = $drive . $t_path;} } }

  # kludge to translate {s|t}_path to {l|r}path
  if ($put) {$lpath = $s_path; $rpath = $t_path;
             $lfile = $s_file; $rfile = $t_file;}
  else      {$rpath = $s_path; $lpath = $t_path;
             $rfile = $s_file; $lfile = $t_file;}

  if ($debug) {print <<EOF;
DEBUG OUTPUT:
  User:   $user
  Server: $server
  Rpath:  $rpath$rfile
  Lpath:  $lpath$lfile
  Create: $create

EOF
  exit if $debug > 1;
  }

############################################################################
###
 
  # now we can log on and grab the file
  $ftp = Net::FTP->new (
    $server,
    Firewall => $proxy,
    Debug => $debug,
    )
    or die "cannot create ftp object: $!\n";
 
  $ftp->login($user, $pwd);
  $ftp->binary;
  if ($ls)
  {
    if ($rpath) {$ftp->cwd($rpath);}
    $r_ls = $ftp->ls();
    print join "\n", sort @$r_ls;
  }
  else
  {
    if ($debug == 2) {print "Inside ftp: create=$create, put=$put,
lpath=$lpath\n";}
    if ($create) {if ($put) {if ($rpath) {$ftp->mkdir($rpath,1);} }
                  else      {if ($lpath) {      MkDir($lpath)  ;} } }
    if ($rpath)  {$ftp->cwd($rpath);}
    if ($lpath)  {    chdir $lpath ;}
    if ($stdout) {if ($put) {$ftp->put("-", $t_file)   ;}
                  else      {$ftp->get($s_file, "-")   ;} }
    else         {if ($put) {$ftp->put($s_file,$t_file);}
                  else      {$ftp->get($s_file,$t_file);} }
  }
  $ftp->quit;
}
 
# use like this: MkDir($path);
sub MkDir {
  my $path = shift;
  my $saved;

  ($saved, $path) = split ":", $path;	# so 1st element != "/C:"
  if ($saved) {$saved .= ":";}
# print "Inside MkDir: drive='$saved', path=$path\n" if $debug;
 
  foreach (split ("\\/", $path)) {
#   print "Making: \'$saved/$_\'\n"  if $debug;
    mkdir "$saved/$_", 0777;
    $saved .= '/'.$_;
  }
}
 
--
Keith W. (Aaron) Roberts        (206) 281-1390 x761     Vmail:
x475
PhotoWorks, Inc.                [formerly Seattle FilmWorks, Inc.]
keith at photoworks.com            Home: kaaron at worldnet.att.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20000606/1c75bea0/attachment.htm


More information about the spug-list mailing list