amcleod has asked for the wisdom of the Perl Monks concerning the following question:

I want to use a Perl script to transfer files to my Android phone with the Net::FTP module. I have installed an FTP server on the phone. Actually tried three different ones. I have set up a suitable id/password on the phone and have created the .netrc file in my home directory on my PC. Testing via the CLI ftp command and the server works fine. (All three of them.)

My perl script however does not. It appears to connect OK but won't allow any of the methods from the module to succeed.

#!/usr/bin/perl -w use feature 'say'; use Net::FTP; $ftp = Net::FTP->new( Host => 'my.host.name', Port => 2221, Debug => 1, Passive=>0 ) or die "Can't connect to server: $@"; say "Connected OK"; $ftp->binary or die "Can't switch to binary mode: $@"; say "Switched to binary mode"; $where = $ftp->pwd() or die "Can't get working directory: $@"; say "\$working directory = $where"; @ls = $ftp->ls() or die "Can't get directory listing: $@"; say "Entries found = ". scalar @ls; $ftp->close();
The output from running this is as follows:
Net::FTP>>> Net::FTP(3.11) Net::FTP>>> Exporter(5.73) Net::FTP>>> Net::Cmd(3.11) Net::FTP>>> IO::Socket::SSL(2.066) Net::FTP>>> IO::Socket::IP(0.39) Net::FTP>>> IO::Socket(1.39) Net::FTP>>> IO::Handle(1.39) Net::FTP=GLOB(0x363bc80)<<< 220 Service ready for new user. Connected OK Net::FTP=GLOB(0x363bc80)>>> TYPE I Net::FTP=GLOB(0x363bc80)<<< 530 Access denied. Can't switch to binary mode: at /home/username/bin/perltest line 9.
The connection appears to be good, but any of the commands I try generate a 530 Access denied. error. This happens no matter which server I activate on the phone.

At first I thought that it was the choice of FTP server that was the issue, but the same results occur for several servers. Then I suspected Android was preventing access to the directory and it's contents but if so, why was I not reeiving any errors when I used the ftp program from the CLI of my PC?

I've used and continue to use Net::FTP to interact with other non-Android hosts without issue, but I can't get it to work with an Android host, and I've tried three of them. Because the CLI client works fine, I have to suspect that Net::FTP is at fault.

Either that, or I've made a really stupid mistake somewhere in my coding?

Suggestions, corrections, observations... all welcome.

Replies are listed 'Best First'.
Re: Issues with Net::FTP and Android
by tobyink (Canon) on Jun 19, 2023 at 17:05 UTC
      Wow! $ftp->login; seems to have done the trick! I feel like an idiot. Now to figure out how to mark this as SOLVED...
        Now to figure out how to mark this as SOLVED...

        You just did.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)