• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 869
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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