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

Hi, I'm attempting to use I-spy, a Perl script which compares FTP or HTTP sites and generates a comparison output. I'm trying to use it on 2 FTP sites.

The FTP portion makes use of Net::FTP, and parses a text file for arguments (2 ftp sites), using the format:

ftp://username:password@hostname//

However, in my case, one of my usernames contains a / (beyond my control), and I can't seem to "escape" it - eg, my username is XX/yyyy, the script bombs out with "Net::FTP: hostname XX invalid" or similar. I've tried changing the username field in the text file to be XX//yyyy, which has the same effect as above, and XX\/yyyy which bombs out with "hostname XX\ invalid".

I'm not sure what Net::FTP is looking for to let me do this; I also couldn't find anything relating to whether or not a / will EVER be parsed correctly as a username by Net::FTP even if passed as an argument and not in the main ftp syntax line.

Also, if anyone knows of any other script/tool already available (pref. free), I'd like to hear about it - this was the only one I could find (searched freshmeat, google).

Thanks,

Glenn

  • Comment on Net::FTP - syntax with username containing /

Replies are listed 'Best First'.
Re: Net::FTP - syntax with username containing /
by kodo (Hermit) on Jul 04, 2002 at 13:49 UTC
    This doesn't have anything to do with Net::FTP I think. I've had a look at the I-Spy-Script, and the part you have to modify there would be:
    sub ParseURL { my($url)= shift; my($protocol, $site, $login, $password); $url=~ /^(\w+):\/*([^\/]+)\/(.*)$/; # chunk the URL components $protocol= uc($1); # preserve matches in real variables $site= $2; $path= $3; if ($site=~ /\@/) { # check for the optional login field ($login, $site)= split("\@", $site); ($login, $password)= # check for the optional password field split(":", $login); return($protocol, $site, $login, $password, $path); } else { # no account information return($protocol, $site, "", "", $path); } }

    Because there the URL gets splitted into different parts which is given to Net::FTP via CheckViaFTP.
    Simply modifiy the split-part and use another char than / to split it. If you don't know how to do that, post a reply here . (I'm short of time at the moment...)

    giant
      If you are going to modify the above subroutine, you'd be better off to leave the URL as is, and do a URI decode on the username and password. (Perhaps also on the path, but I don't know how that's used in the rest of the program). Then escape the slash in the username with %2F.

      Abigail

      OK, I'm ready to admit defeat in trying to modify the separator regex:

      $url=~ /^(\w+):\/*([^\/]+)\/(.*)$/;

      The way I'm reading this is: between  /^(\w+) is $protocol, between  \/*([^\/]+) is $site, and  \/(.*)$ is $path.

      So, based on the above, if I use a comma separator for the $site portion, the line should look like:

      $url=~ /^(\w+):\/*([^\/]+),(.*)$/;
      and the appropriate line in my text file looks like:

      ftp://XX/yyyy@123.456.789.012,/

      However, when I then run the script, I get several "uninitalized value" errors, one for the pattern match ($site=~ /\@/), one for a line trying to use $host, the other for a line trying to use $path.

      Just for kicks, I tried substituting a comma wherever there was \/, but I got minor variations on the above errors. I also tried substituting \; , but that didn't seem to make a difference.

      So, any help appreciated - if I can learn something about regexs today I will be happy.

      Thanks,

      Glenn

        Sorry, just realized the contents of the file should be:

        ftp://XX/yyyy:password@hostname,/

        Thanks,

        Glenn

      Whoops. I confused myself, as the syntax in the file is similar to Internet Explorer's ftp syntax - brain fart.

      My bad, thanks for the help.

      Glenn