Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 856
  • Last Modified:

get a file with variable filename using ftp

I want to get a file using ftp from a remote host, but the file name is variable:
fix_part.xyz
in which xyz is timestamp, it can be 1191690121 and changed daily
so i can not use a fix file name to get it
how do I solve this???
0
nanoterabeta
Asked:
nanoterabeta
  • 4
  • 3
  • 2
2 Solutions
 
TalmashCommented:
as for "open" command, same for ftp:

this code :
for $p (0..27) {
    open(SRC,"tmp_2962_rx_$p");
}
replace:
    open(SRC,"tmp_2962_rx_0");
    open(SRC,"tmp_2962_rx_1");
   ...
    open(SRC,"tmp_2962_rx_27");
0
 
nanoterabetaAuthor Commented:
can you explain furthermore Talmash??
0
 
TalmashCommented:
send me the ftp command for fixed file name
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nanoterabetaAuthor Commented:
if filename is "IPmeas.202.yes", I  just simply use this:

$ftp=Net::FTP->new("$host",DEBUG=>0);
$ftp->login("","");
$ftp->ascii;
$ftp->get("IPmeas.202.yes","/IPmeas.202.yes");

but if it is "IPmeas.202.yes.xyz" and I don't know for sure what xyz is for today, I can't get it
0
 
TalmashCommented:
replace:
$ftp->get
to
$ftp->ls or $ftp->dir

to get the files names, parse them and fetch out the needed file
0
 
Adam314Commented:
If you know what the timestamp is, and it's in $timestamp, then use:

use Net::FTP;

my $ftp = Net::FTP->new("some.host.name", Debug => 0)
    or die "Cannot connect to some.host.name: $@";

$ftp->login("anonymous",'-anonymous@')
    or die "Cannot login ", $ftp->message;

#If you don't know the timestamps for the files you want, do this
#if you do know the timestamps, skip this step (I'm assuming the names will be in @files)
my @files=$ftp->ls()
@files=grep {/^fix_part\./} @files;

#Get the files
foreach (@files) {
    $ftp->get("$_") or warn "get failed ", $ftp->message;
}

#quit
$ftp->quit();
0
 
nanoterabetaAuthor Commented:
are you sure that this will work??? @files=grep {/^fix_part\./} @files;
0
 
TalmashCommented:
not recommended.

afaik, it won't work.
print it out BEFORE and AFTER the action, and see.
I never do such actions.
0
 
Adam314Commented:
I don't see anything wrong with that.  The grep will get the files that begin with the literal "fix_part.".  
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now