Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7447585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:39:21+00:00 2026-05-29T12:39:21+00:00

I started programming in perl few months back and this is my first question

  • 0

I started programming in perl few months back and this is my first question on stackoverflow.com. I hope I can get a solution.

So I want to copy some files from an ftp server. The file names are in this format:

abc_201149_cde_07_fgh_include_internal 

In this example the numeric part gets changed on weekly basis, e.g. 201149 says year = 2011 and week = 49. Similarly, 07 says which version it is.

I have copied all the file names into one file called “sdk_link.txt” and I am reading each file name from this and then copying to my local PC:

use Net::FTP;
use File::Copy;
$Login = "<redacted>";
$Pwd = "<redacted>";
$ftpHost = "<redacted>";
$ftpFolder = "/daj/dhakj/ahdakl/abc_201206_def_05";
$ftp=Net::FTP->new($ftpHost,Timeout=>100);
if ($ftp) 
{
    print $ftp->message;
}
$ftp->login($Login,$Pwd);
print $ftp->message;
$ftp->cwd($ftpFolder);
print $ftp->message;
open FILE,"sdk_link.txt" or die $!;
while($test=<FILE>) 
{
    chomp($test);
    #Copy the file
    copy("$test","/testing"); 
}
$ftp->quit;

I want to run this script every week on Windows. How can I make the numeric part change so that the correct files get downloaded?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:39:22+00:00Added an answer on May 29, 2026 at 12:39 pm

    Well, the obvious answer is to keep a template on file, and insert the correct numbers. For example:

    echo abc_%s_cde_%s_fgh_include_internal | 
        perl -MPOSIX -nE 'say sprintf $_, strftime("%Y%U", localtime()), "07";'
    

    Output:

    abc_201207_cde_07_fgh_include_internal
    

    So that if you’d have a file with templates, you can use %s to insert strings, and provide arguments either from your own list of arguments, or dynamically, as you prefer. E.g.:

    my $year = "2011";
    my $week = "49";
    my $ver  = "07";  # Strings or numbers does not really matter
    
    open my $fh, '<', "sdk_link.txt" or die $!;
    
    while (<$fh>) {
        my $file = sprintf $_, $year, $week, $ver;
        copy($file, "/testing") or die "Copy failed for file $file: $!";
    }
    

    I am not so sure File::Copy::copy works as intended for remote files, but that’s another question. I believe Net::FTP::get() might be what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ever since I started programming this question has been annoying me, not where is
I started programming C# applications when the 1.0 framework was first released. I worked
When I first started programming, I wrote everything in main. But as I learned,
I have just started programming and have made a few small applications in C
Ever since I started programming this has been something I have been curious about.
When I first started programming in .NET I used try/catches all the time. I
I recently started programming my first Cocoa app. I have ran into a problem
Not long ago I started programming Python with Django. Sometimes I get strange errors
I just started programming in Objective-C. Prior to this I was primarily a C#
Since I've started programming in Java I have been wondering this (about a year

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.