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

I am hoping to use the Net::FTP to download a remote file from an IBM Mainframe when a user clicks views a page. I currently have a program that will then read that file and display the contents in a chart. The site is on our Intranet and is hit around 10 times a day. Is their some way that I can access the Net::FTP from Perl Script.

Also, I am running ActivePerl v.5.6. I have been attempting to install Net::FTP and I haven't been able to do so properly. I have tried installing from the PPM and I recieve an error that it cannot locate the PPD file for that module. Any thoughts would be appreciated.

Here is a copy of the script I am trying to run to accomplish the FTP:

# place the wip2.rpt file in the information\production file
use Net::FTP;
$path = "F:\InetPub\wwwroot\Information\Production\";
$file="'RPP.OI0800M1'";

$server="ibmmain";
$user="cmms";
$pw="cmms";
$ftp = Net::FTP->new($server);
$ftp->login($user,$pw);
$ftp->get($file, wip2.rpt);
$ftp->quit

Am I doing something wrong?

Replies are listed 'Best First'.
Re: FTP Problems
by Beatnik (Parson) on Jan 26, 2001 at 20:46 UTC
    $file should probably be $file = "RPP.OI0800M1";. Also use $ftp->get($file, $path."wip2.rpt"); instead.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: FTP Problems
by Fastolfe (Vicar) on Jan 26, 2001 at 22:34 UTC
    Your problem probably stems from the fact that you are using backslashes (\) in your interpolated (double-quoted) string in your $path assignment. Either use single-quotes or escape your backslashes by doubling them. Your last quotation mark is being interpreted as a literal quotation mark in the string, which is totally screwing up your next few lines of code, because Perl is treating it all as part of the same string.

      Um, please try your first suggestion youself. ;) \ is still special inside of single quotes and will escape the trailing delimiter, just like it did in the original code. Yes, if the \ is not followed by another \ or your string delimiter (or either of your string delimiters if using nesting delimiters as in q{}), then the \ will be preserved within single quotes. I discourage that because I feel that it leads to mistakes when the \ is followed by one of these characters. If someone as sharp as Fastolfe can get snagged by this, then I think my paranoia is justified. (:

      I always double backslashes when I want a backslash unless I'm in a "here doc".

              - tye (but my friends call me "Tye")
        Well, if I were doing this in my own application, I would have tested my solution first and realized the mistake. You're right, though. Heh.

        If you ask me, I hate the fact that back-slashes are special at all within single-quoted strings, precisely for this problem. People make the assumption that single-quotes mean no interpolation is done, that they are safe putting whatever they want in the string. Backslashes are essentially ignored/safe except in the case of a second backslash or a single-quote itself. I might argue that backslashes be totally ignored/unspecial in a single-quoted string. Injecting single quotes might be done by doubling them up.

      Just out of curiosity, why not simply use forwardslashes instead? I use them consistently in win32 applications with no issue. Am I missing something?
        No, you're not. They'll work fine in most any case.
Re: FTP Problems
by myeager (Initiate) on Jan 27, 2001 at 02:48 UTC
    I agree with the other posts that the / should be in place of the \ mark. You also never used the path of the file. I've run some FTP scripts of my own. I did it this way :
    $host = "servername";
    $user= "username";
    $pw = "password";
    $ftp = Net::FTP->new("$host", Debug=>0);
    if($ftp){
        $ftp->login($user, $pw);
        $ftp->cwd("directory_path/subdirectory/here");
        $ftp->get("filename_in_directory");
    }