Solved

ftps file download

Posted on 2011-03-25
6
354 Views
Last Modified: 2012-05-11
I am accessing an ftps server. I want to get the file that has todays date,
for example the file name starts with XXXXDownload20110312+/d example:
ABCDDownload20110312023117.xml.gz
I login and do a pwd and go to the correct directory. I then do a list
and from the list, I use DUMPER to find the file matching the date, I then
do an ftps->get($filename) to get the file because with ftps-> get ($filename) the $filename
has to be the exact file name and in quotes for the get  work.

Three questions:

1. For the line of code Dumper($ftps->list()) with a date or a date pattern such as *20110312*
I put an output below and you will see that I can
see 16 files at time, if there are more than 16 files, I can't see beyond,
So far, the daily file has been on the displayed 16 files but I
fear that one day my daily file won't be in the displayed 16 files so I won't be able to get it.
I am not sure what the criteria is for list() to determine what 16 files it lists.
2. Is there a way to get the file using ftps->get but without the exact
filename. ftps->get(an expression for a file name), example get("*20110312*"); i've tried
this but it does not work. I don't think this is supported.
3. given the snippet of code can you suggest improvements?

thanks

snippet:

use Data::Dumper;
use Net::FTPSSL;

my $ftps = Net::FTPSSL->new('x.y.z.w',
                              Port => 10021,
                           #   Encryption => 'E',
                              Debug => 1,
                              Croak => 1)
    or die "Can't open ftps";
$ftps->login('abcd', 'xyz');
$ftps->cwd("download_dir") or die "cannot go to the path: ", $ftps->last_message;
my $ret = Dumper($ftps->list())
    or error("Command error, $ftps->last_message");

foreach my $file (split(/;/,$ret)){
  print ($file."/n");

! here I hardcoded to get the file for march 24th
  if ($file =~ /\w+20110324\d+/)
  {
     my $result = $&;
     print "my result is: $result\n";
     $result =~ s/\/n//;
     print "my result updated is $result\n";
     $results = $result.".xml".".gz";
     print "my results is $results\n";
     $results =~ s/\/n//;
     print "my results updated is $results\n";
  }
}

$ftps->get($results) or die "cannot get the file :", $ftps->last_message;
$ftps->quit();


for #1 here is an example of output from list() using snippet.



<<< 226 Directory send OK.
$VAR1 = '-rw-r--r--    1 516      501         11115 Mar 12 00:01 ABCDEDownload20110312020109.xml.gz'/n
$VAR2 = '-rw-r--r--    1 516      501          4760 Mar 13 00:01 ABCDEDownload20110313020107.xml.gz'/n
$VAR3 = '-rw-r--r--    1 516      501          2442 Mar 14 00:01 ABCDEDownload20110314020109.xml.gz'/n
$VAR4 = '-rw-r--r--    1 516      501         13629 Mar 15 00:01 ABCDEDownload20110315020103.xml.gz'/n
$VAR5 = '-rw-r--r--    1 516      501         10807 Mar 16 00:01 ABCDEDownload20110316020137.xml.gz'/n
$VAR6 = '-rw-r--r--    1 516      501         11081 Mar 17 00:01 ABCDEDownload20110317020116.xml.gz'/n
$VAR7 = '-rw-r--r--    1 516      501         18348 Mar 18 00:02 ABCDEDownload20110318020200.xml.gz'/n
$VAR8 = '-rw-r--r--    1 516      501          8885 Mar 19 00:01 ABCDEDownload20110319020127.xml.gz'/n
$VAR9 = '-rw-r--r--    1 516      501          4597 Mar 20 00:01 ABCDEDownload20110320020057.xml.gz'/n
$VAR10 = '-rw-r--r--    1 516      501          1684 Mar 21 00:03 ABCDEDownload20110321020301.xml.gz'/n
$VAR11 = '-rw-r--r--    1 516      501          1387 Mar 22 00:02 ABCDEDownload20110322020220.xml.gz'/n
$VAR12 = '-rw-r--r--    1 516      501         12222 Mar 23 00:01 ABCDEDownload20110323020120.xml.gz'/n
$VAR13 = '-rw-r--r--    1 516      501          8665 Mar 24 00:01 ABCDEDownload20110324020111.xml.gz'/nmy result is: ABCDEDownload20110324020111
my result updated is ABCDEDownload20110324020111
my results is ABCDEDownload20110324020111.xml.gz
my results updated is ABCDEDownload20110324020111.xml.gz
0
Comment
Question by:Johannne1
  • 4
  • 2
6 Comments
 
LVL 16

Assisted Solution

by:AlexPace
AlexPace earned 500 total points
ID: 35217514
Well if you are not determined to do it as a unix perl script and instead you just want to get it done now as in 5 minutes ago you could do run the Robo-FTP command script below as a service on a Windows box.

Robo-FTP can parse the directory listing returned by the remote FTPS server to find the file you you actually want to download..
LOG "daily_script.log"
TRACELOG "daily_trace.log"
:loop_top
SETRIGHT year = %datetime 4
SETEXTRACT month = %date "-" 1
SETEXTRACT day = %date "-" 2
SET filespec = "*Download" + year + month + day + "*"
LOGMSG filespec  ;; this may be helpful for debugging
FTPLOGON "127.0.0.1" /user="userID" /pw="secret" /servertype=FTPS /trust=all
RCVFILE filespec
FTPLOGOFF
CRON "crontab.txt"  
GOTO loop_top

Open in new window

You'll need to put the server's dns name or address and your username and password on that row with the FTPLOGON command.
The crontab.txt file would be in the Robo-FTP install folder and would contain one line... for example to have it run at 30 minutes after 6am every day the one line would be:
30 6 * * *

Open in new window

The way this code is structured now it will run once when you first kick it and then at 6:30am each day after.  To change it so it waits for the next 6:30 before running just move the CRON line from down near the bottom to up near the top right after the top of the loop and right before the row where you get the current year.

Sorry if you really need a perl solution and this post wasn't helpful.
0
 

Assisted Solution

by:Johannne1
Johannne1 earned 0 total points
ID: 35217603
Hi AlexPace,
Can I use this in a korn script? I already have a korn script that was calling my perl script.
J.
0
 
LVL 16

Accepted Solution

by:
AlexPace earned 500 total points
ID: 35217625
I'm sorry this is Robo-FTP command script language so its no good to you unless you have a WinDoze box.  
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Johannne1
ID: 35487497
No comment
0
 

Author Comment

by:Johannne1
ID: 35487499
Can you please take this question off my list.
0
 

Author Closing Comment

by:Johannne1
ID: 35510955
I tried to cancel this question many times. I wrote twice to the help desk to two different addresses but I was unssucessful. I answered my own question within the question. The solution was helpful but PC based instead of unix based.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now