ftps file download

Posted on 2011-03-25
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:
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?



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;

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
Question by:Johannne1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 16

Assisted Solution

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"
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 "" /user="userID" /pw="secret" /servertype=FTPS /trust=all
RCVFILE filespec
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.

Assisted Solution

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.
LVL 16

Accepted Solution

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.  
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.


Author Comment

ID: 35487497
No comment

Author Comment

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

Author Closing Comment

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.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
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…
Six Sigma Control Plans

627 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