Sponsored Content
Top Forums Shell Programming and Scripting Broke Perl Script Second pair of eyes NET::FTPSSL Post 302275975 by Styles on Monday 12th of January 2009 06:34:02 PM
Old 01-12-2009
Question Broke Perl Script Second pair of eyes NET::FTPSSL

Hi all,

Let me first start out by saying I'm a perl newbie and hope somebody can help, for the life of me I can't figure out why my script will not find and download a remote file via FTPSSL. What it's supposed to do is find the latest file named simple-test-case_("dd-MM-yyyy-hh-mm-ss").csv i.e.
Quote:
simple-test-case_09-01-2009-08-17-51.csv
and download it. But when I run it (no error or warnings) it acts like it does not find the file and hence not download it. A second pair of eyes and guidance would be much appreciated. I personally feel it's my regex.

Code:
use strict;
use warnings;
use Net::FTPSSL;
use Getopt::Long qw(:config no_ignore_case);


my $hostname = '127.0.0.1';
my $username = 'testuser';
my $password = 'testpass';
my $port = '21';
my $directory = '/';
my $verbose = '1';
my $passive = '0';
my $timeout = "30";
my $version = "0.0.2";
my $input_dir = "input";
my $output_dir = "output";
my $input_trg_file = "simple-test-case.csv";
my $input_csv_file = "simple-test-case.trg";
#Bellow var will be used later
my $output_file = "simple-test-case*.csv";
#
my $encryption = "E";

# creating connection and starting the test

my $ftps = Net::FTPSSL->new($hostname, Debug => $verbose, Port => $port, Encryption => $encryption ) or die "ERROR: Cannot conect to $hostname\n";

if (!$ftps->login("$username","$password")) { 
  print "ERROR: Sever says: ", $ftps->last_message;
  exit 2;
}
if ($input_trg_file eq "") {
  if (!$ftps->list("$directory")) { 
    print "WARNING: server says: " , $ftps->last_message;
    exit 1;
  } else {
    print $ftps->last_message;
  }
} else {
    if (!$ftps->cwd("/$input_dir")) {
      print "WARNING: server says: " , $ftps->last_message;
    exit 1;
  } else {
      if (!$ftps->put("$input_trg_file","/$input_dir/$input_trg_file")) {
        print "WARNING: server says: " , $ftps->last_message;
        exit 1;  
    } else {
      if (!$ftps->put("$input_csv_file","/$input_dir/$input_csv_file")) {
        print "WARNING: server says: " , $ftps->last_message;
        exit 1;
      } else {
        if (!$ftps->cwd("/$output_dir")) {
          print "WARNING: server says: " , $ftps->last_message;
          exit 1;
          } else {
          sleep(10);
          my @lines = grep { /^simple-test-case./i } $ftps->list();
          foreach my $name (@lines) { 
          if (!$ftps->get("$name, /tmp/$name")) {
              print "WARNING: server says: " , $ftps->last_message;
            } else {
              my @message = $ftps->last_message;
              chomp @message;
              print "OK: ", "$message[0] $message[1]\n";
              exit 0;
             }
           }
         }
       }
     }
   }
 } 

$ftps->quit;

Thanks in advance,
Eric
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Best place on the net to get Perl tutorials ?

I am looking for a full Perl course on internet (tutorial) to learn everything about Perl. I already know a bunch of programing languages. I have started Unix interests this year ever since I installed Ubuntu Linux on my PC AND I also got a job at IBM doing software distributions with... (1 Reply)
Discussion started by: Browser_ice
1 Replies

2. Shell Programming and Scripting

Need some help with this script -- extra eyes

I have two issues with this script. 1. I cannot seem to get my counters to count correctly. 2. My function to eject to CAP1 or CAP2 is hung in a loop and doens't exit back to the previous function. I would like to be able to select which cap to eject to . Each cap holds only 40 tapes, so when one... (15 Replies)
Discussion started by: gzs553
15 Replies

3. Shell Programming and Scripting

Net::SSLeay or Net::FTPSSL

Hello, I ran into an issue in one of my monitoring scripts. If I use the public ip address in my connection string everything works, but if I switch the connection string ip to 127.0.0.1 or the internal ip I get, " Connection refused at... (1 Reply)
Discussion started by: Styles
1 Replies

4. Shell Programming and Scripting

Net::Ftp in perl

I am trying to execute a script in another server, i used Net::Ftp module How to execute unix command in another server by using Net::Ftp module.. #!/usr/bin.perl ### Perl script to $ftp->login($user_name,'password') or die "Cannot login ", $ftp->message;... (2 Replies)
Discussion started by: pritish.sas
2 Replies

5. Shell Programming and Scripting

Would appreciate a quick second set of eyes on a script (regarding doing things in the background)

What I'm trying to do is leave a tcpdump running all the time on a server, and at the end of every day kill it and start a new one. For some reason my boss doesn't want to set this up as a cron job, so I've come up with the following.: #!/bin/bash PCAPFILE=/tmp/mgmt.$(date... (8 Replies)
Discussion started by: DeCoTwc
8 Replies

6. Windows & DOS: Issues & Discussions

Running perl script from a VB.NET windows service

Here is the snippet of the code that I'm trying to execute. Stat of the service does not launch perl script. OnStop works fine. Please could you help here. Public Class Service1 Protected Overrides Sub OnStart(ByVal args() As String) ' Add code here to start your service. This... (0 Replies)
Discussion started by: hansini
0 Replies

7. Shell Programming and Scripting

Have a find/replace perl script thats broke

Hello Folks, #!/usr/bin/perl use File::Find; open F,shift or die $!; my %ip=map/(\S+)\s+(\S+)/,<F>; close F; find sub{ if( -f ){ local @ARGV=($_); local $^I=""; while( <> ){ !/#/ && s/(\w+)\.fs\.rich\.us/$ip{$1}/g; print; } }... (8 Replies)
Discussion started by: richsark
8 Replies

8. Shell Programming and Scripting

Unable to get the size of remote file using Net::FTP Perl Script

Hi, I am using below piece of code to get the size of the remote file. $ftp->cwd($destination) or $error=$ftp->message; if(!$error) { $ftp->put($file) or $error=$ftp->message; print "FTP size = \n"; ... (3 Replies)
Discussion started by: FarooqOnline
3 Replies

9. Shell Programming and Scripting

Bash script to create rsa key pair

Hello all, I am setting up a cluster of Mac Pro's which need to be able to talk to a master computer, traffic between the nodes and the master needs to take place without a ssh key. I need a script that will create a security key, save it to the default place, enter the password as no password.... (2 Replies)
Discussion started by: sdl27789
2 Replies

10. Shell Programming and Scripting

Perl Net::IP not working

Experts - I have a snippet of code I can't figure out. I was hoping someone could help me here. I have a file of IPv6 address that I need to format correct. Example in: 2620:0:2d0:200::7 2620:0:2d0:200:a0:c 2620:0a:3f0:200:a0:c I need to convert them to:... (3 Replies)
Discussion started by: timj123
3 Replies
All times are GMT -4. The time now is 01:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy