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

  • Home
  • SEARCH
  • 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 8638335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:42:13+00:00 2026-06-12T10:42:13+00:00

The LS command is not giving what I expect in Net::FTP. I expected it

  • 0

The LS command is not giving what I expect in Net::FTP. I expected it to return an array of strings (filenames), but I get an array, containing an array of strings.

use strict;
use Net::FTP::Common;

my ($host, $user, $pw) = ('<ftp site>', 'user', 'pw');
my $ftp = new Net::FTP($host) || die;
$ftp->login($user, $pw) || die;

my $pwd = $ftp->pwd();
my $subDir = 'subdir/';
my $pattern = '*.txt';
$ftp->cwd($subDir); 

$ftp->pasv(); # passive mode
my @files = $ftp->ls($pattern) || die;

$ftp->cwd($pwd); 

The files array looks like this, for example:

@files[@array[0]] = ‘filename.txt’;

I’ve also tried not Changing Directories, and just doing $ftp->ls('subdir/*.txt'); with the same results.

Why is it doing this? I am misunderstanding the return value? This is on WINDOWS.

  • 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-06-12T10:42:14+00:00Added an answer on June 12, 2026 at 10:42 am

    First, you should be using

    use Net::FTP;
    

    instead of

    use Net::FTP::Common;
    

    since you use Net::FTP and not Net::FTP::Common.

    Now on to your problem.


    The documentation says:

    In an array context, returns a list of lines returned from the server. In a scalar context, returns a reference to a list.

    which surely means

    In list context, returns a list of the lines returned by the server. In scalar context, returns a reference to an array of these lines.

    You’re calling it in scalar context. You want

    my $files = $ftp->ls($pattern)
       or die;  # || would work, just not idiomatic.
    
    for my $file (@$files) {
       ...
    }
    

    You could call ls in list context, then then you’d sacrifice error checking.

    # No way to determine whether empty means error or no files.
    my @files = $ftp->ls($pattern);
    
    for my $file (@files) {
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I type saklfjsklj in bash, I get: bash: saklfjsklj: command not found Is
In command prompt of mysql 5.1 I am not able to use Date function.It
I tried bake with Cakephp 2.0.4 stable with 'cake bake' command But it's giving
I'm trying to run this SQL command but it's giving me an error that
I am not able to execute this query getting ORA-00933: SQL command not properly
I have read this thread when I got the the git: command not found
Why this curl command does not work in CMD. It should downlaod a html
I am unsure why is this rsync command is not syncing? rsync -v -e
I am running Hadoop 1.0.1 on Ubuntu 11.10. ./bin/start-all.sh command does not prompt any
Is there a way to combine distinct with another command to print not only

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.