in reply to Re: Net::FTP usage
in thread Net::FTP usage

It is showing me the filename that I expect, just like when I was debugging. Like the first file is sudolog_2010Jul_Infodevl. Now is says "Cannot open Local file sudolog_2010Jul_Infodevl: A file or directory in the path does not exist pointing to the $ftp->put statement. Earlier in the code I cd to the local directory. Should that still exist for this FTP? Ken

Replies are listed 'Best First'.
Re^3: Net::FTP usage
by Corion (Patriarch) on Aug 13, 2010 at 14:12 UTC

    You never call chdir, so you never change your working directory for your Perl script.

    Maybe you want to read about glob instead of shelling out to write the entries of a directory into a file?

    Also, I still don't believe you that you do not have whitespace at the end of the elements of @array.

    use File::Glob 'bsd_glob'; my @files = bsd_glob "$tempdir/sudolog*"; print "Found file [$_]\n" for @files;

    ... will read all the files named sudolog* from the directory given in the $tempdir variable.

        Is the $f =~ s/\s+$// ; statement doing the chomp function?

        In this context, it's probably accomplishing more or less what the chomp would have been intended to accomplish. There are however technical differences, e.g., the + causes the substitution to remove as much trailing whitespace as it can find, so if the line ends with twenty-seven spaces in a row followed by three tab characters, a carriage return, and a line feed, they'll all be taken off; chomp would probably only take the CRLF, or maybe even just the linefeed, depending on the value of $/.

        For more details about the substitution, read the chapter on regular expressions in your favorite Perl book. Don't worry too much about chomp for now (until you have been using Perl for a while longer); if you know how to use s///, you can probably get by without chomp for the time being. (Regular expressions, on the other hand, are pretty much impossible to live without. The internet as we know it could more likely exist without integrated circuits than without regular expressions.)

Re^3: Net::FTP usage
by dasgar (Priest) on Aug 13, 2010 at 15:03 UTC

    Based on your die statements, I don't think that the issue is with the $ftp->put line. The error message that you mentioned ("Cannot open Local file sudolog_2010Jul_Infodevl: A file or directory in the path does not exist") looks like the die statement from where you tried opening the file.

    I agree with Corion about the problem being that you're in the wrong directory. Unless your Perl script is run in the same directory as the 'lsfiles' file that you're trying to create, the open command will look in the path that the Perl script was invoked from and will fail to find it.