[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

FTP directory listing...

I have a perl script that puts a file on a ftp site.  I need a way to verify that the file is actually on the ftp site.  Manually I'd type "dir file_name".  I can't seem to get that to work using PERL.  Can someone help?  I'm also open to "better" ways of verifying that the file was recieved.  Thanks!
1 Solution
Kim RyanIT ConsultantCommented:
If you are using the Net::FTP module,
use Net::FTP;
$ftp = Net::FTP->new($host_ip);
# get list of files from current dir
@remote_files = $ftp->ls;

To be really sure your file got there, you could fetch it back again as a different name and check the size is the same as the one you sent.
cotec1Author Commented:
# get list of files from current dir
@remote_files = $ftp->ls;

This works, but it returns all of the files in the directory.  How can I filter out just the one I sent - $File_to_send?
grep{$_ eq $File_to_send} @remote_files;
# test if that file exists
-e $file_name || &error;
# it has a non-zero size (returns size)
-s $file_name || &error;

## there are other file test operators, about 2 dozen.  What do you want to accomplish?
cotec1Author Commented:
This is what I did.  It works well enough, for now.

    @remote_files = $ftp->ls($file);
    print "\nChecking for file on ftp site...\n";
    print "@remote_files      <--(your file should be listed here)\n";

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now