I am having a problem using the Net::Ftp.pm module. I can successfully connect to an ftp server, and retrieve the directory listing in an array, but I can not retrieve the attributes on the file e.g. file permissions, modification age into variables.

@dir = $ftp->dir();

This retrieves information on a file, and if I do:

print "@dir[0]";

it will print all the information and attributes of the file, but I would like to assign each attribute to a variable. e.g.

$chmod = @stat[0];

Is there anyway of doing this? I tried to use the split function but it would be no good as there is no key character to split it by.

You may be able to write a regular expression that extracts the data you want from the directory line. Or another, probably simply, solution is to use the unpack function to extract the data.

In boh cases, you should be aware that the format of the directory listing isn't standard and will change between different FTP servers. This means that the regular expression or unpack template that you use will need to change as you connect to different servers.

The code you have provided works fine until the interpreter reaches unpack. In my server error log is says 'Invalid Argument'. I simply copied the code provided and just added it into mine. Do you know what the problem might be?

I also have no idea how the code works, the only time I have had use for 'pack' and 'unpack' was for converting char to ascii and vice-versa. Please explain the code, I understand the foreach loop, but I have no idea what 'unpack' does to the variable in the for loop.

As I couldn't get it working I finally used:

foreach ($ftp->dir()){

@statarray = split(" ", $_, 9);

}

This gave me an array of stats for the file. It also works on filenames with spaces. Is this a good way of doing it?

The code you have provided works fine until the interpreter reaches unpack. In my server error log is says 'Invalid Argument'. I simply copied the code provided and just added it into mine. Do you know what the problem might be?

Oops yeah. I got the templates the wrong way round. Where I had

Code

my $unpack = '10a4a5a7a15a12a*a';

It should have been

Code

my $unpack = 'a10a4a5a7a15a12a*';

Sorry for the confusion. you would probably have been able to work out the problem yourself if you'd read the documentation for unpack which I directed you to.

In Reply To

I also have no idea how the code works, the only time I have had use for 'pack' and 'unpack' was for converting char to ascii and vice-versa. Please explain the code, I understand the foreach loop, but I have no idea what 'unpack' does to the variable in the for loop.

I am having trouble with another command I would like to send to the remote web server using net::ftp.pm, I would like to change the CHMOD settings on the file, but there is no command for it in ftp.pm.