Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl mdtm FTP command

Status
Not open for further replies.

BStopp

Programmer
Dec 29, 2003
29
US
Hi everyone, I'm writing a script that will log into an FTP server, retrieve a list of files, then get modified time on that perticular file. For some reason, all my script does is return an empty variable. Here's what I have:

$ftp = Net::FTP->new($SERVER)
$ftp->login();
$ftp->binary();
@files = $ftp->ls();
foreach $cur_file (@files)
{
$file_date = $ftp->mdtm($cur_file);
print "$file_date $cur_file\n";
}


Now i'm only printing out the file_date so i can get the format returned for later evaluations. But right now it returns an invalid character or "". The CPAN Net::FTP manual says that the mdtm() function will return the "modification time" of the file passed. I've tried putting the $cur_file in quotes, i've even tried passing it the specific directory the list of files are in, but still no luck. Anyone know why this command isn't working or maybe another way of getting the modified time from a file through an ftp session?

B. Stopp
 
Does the command work when you naked ftp into the system manually? Perhaps the server you are connecting to does not support this feature..

 
You're setting the mode to binary, yet you're expecting a directory listing back (I would've thought this would be ascii)
when you retrieve the ls() command what's in the array?

--Paul
 
Does the command work when you naked ftp into the system manually? Perhaps the server you are connecting to does not support this feature.

There is no such "mdtm" command in an FTP session. My impression from the CPAN perl documentation was that the module retrieved the time from the long format of an ls statment on the file, I haven't dug into the module coding to see where it gets its info from.

You're setting the mode to binary, yet you're expecting a directory listing back (I would've thought this would be ascii)
when you retrieve the ls() command what's in the array?


Setting the ftp session to binary is just a way of transferring data faster. Data is converted to binary at the remote host, then converted back at the local host to speed the transfer bit rate along. It isn't a good idea when transferring files unless the two systems utilize the same OS/Enviornment. The two I am working with do.

To answer your question, the ls() command returns a listing of all files in the directory specified, one per element in the array.

Any thoughts as to why the mdtm method isn't working or another way to extract the information i need from a given file?
 
Does the command work when you naked ftp into the system manually? Perhaps the server you are connecting to does not support this feature.

There is no such "mdtm" command in an FTP session. My impression from the CPAN perl documentation was that the module retrieved the time from the long format of an ls statment on the file, I haven't dug into the module coding to see where it gets its info from.


My assumption on the mdtm() function was wrong. It is a ftp command that apparently is not supported by our servers. Thanks for the help.

B. Stopp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top