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.


In reply to Issues with Net::FTP and Android by amcleod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.