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

I am trying to read a file and ftp the files listed to a unix server. this code works for one file but when i have multiple files it complains saying that file cannot be found. Looks like the directory is not changing properly. I am using chdir to change the directories in the local m/c. This script runs fine on my pc where i have 5.8.7 but on the m/c i have 5.3 it doesn't.....any ideas on how this can be fixed?

Replies are listed 'Best First'.
Re: ftp with perl
by runrig (Abbot) on Nov 22, 2005 at 23:21 UTC
    You are doing a chdir in a separate process which doesn't affect the perl process...perl has a chdir function; you should use it and check for success/failure:
    chdir $home or die "Can't chdir to $home: $^E";
      Thanks so much I was able to fix it..... It is the chdir that is not going to the right directories. After modifying the paths it is working.
        Please consider restoring the code in your original node. None of the answers here make sense when there's nothing to refer to. The questions and answers are for the benefit of everyone. And remember to put <code>...</code> tags around the code. Thanks.
Re: ftp with perl
by GrandFather (Saint) on Nov 22, 2005 at 23:18 UTC

    That code simply can not run. use strict; use warnings for a start. As it stands there are a bunch of undef vars in both subs that are local to the subs. That surely can not be how your code is actually structured.

    Replace the ftp calls with prints to show the parameters that are being used. Something there is bound to be bogus

    See I know what I mean. Why don't you? :)


    DWIM is Perl's answer to Gödel
Re: ftp with perl
by ptum (Priest) on Nov 22, 2005 at 23:17 UTC
    It would really help if you would include any error messages that were produced by the script that failed. You may also want to update your original posting to format your code in a more readable fashion. Have you tried inserting any debugging statements along the way?

    Are you sure that the userid/password you are using exist on the machine where it doesn't work? Are you sure that the FTP port is open on that machine, or are there any firewalls involved?

    Have you thought about using a more secure transfer protocol, like scp?

    No good deed goes unpunished. -- (attributed to) Oscar Wilde