FTP - Get the file date and time on the remote server

I would like to know if there is a way to get the date and timestamp of the file that is being FTP from the remote server using shell script. Currently the get command from FTP will have current date and timestamp. Tried the earlier suggestion 'HardFeed' but still getting the current date and time and not the date and timestamp on remote server. Appreciate any help. Thanks

Is the remote system doing a push or are you doing a pull of the files. If the remote system is doind a push of the files onto your system, then you may want to include the date and time of the file built into the name of the file and when it comes over to your local machine there will be a visual indication of the date and time when the file was last created/modified in the remote system.
It may be possible to do the same if you are doing a pull from the remote system too.

Basically when trying to get a file from remote server, it will be a 'get' (pull). But I need to get the file with the date and timestamp which is on the remote server. So it is a pull from the remote server, but gets the file with current date and timestamp on it and not the date and timestamp on the remote server. I need to know how this can be achieved using shell script. Thanks

comp.unix.shell

A complete solution is not possible and an incomplete solution would break the "freshen" feature in HardFeed. The date format changes for older files. The time is replaced with the year. HardFeed then has no time to parse. So it sets the time to "0000" making it seem that the file was created at midnight. If the local and remote copies are both old, the local timestamp will not be later than the remote timestamp and the file will be retrieved. This means that superfluous file retrieves can sometimes happen when both the local and remote copy have aged enough that the time is replaced by the year. After one superfluous retrieve this will never happen again. If HardFeed set the timestamp of the local file back to the past, this would cause older files to be retrieved on every run.

vgersh99,
As suggested in comp.unix.shell, rcp is not an option, Since you need to have privilege on the remote server which is handled by other group.

is 'tar' an option as suggested?

Maybe using tar is not a pefect solution, but it is a robust one, I think.

Nope. The file is an encrypted file and they post as is. Cannot compress the file and we do not have access to make any changes on the remote server.

how about this(under ftp prompt)

quote MDTM <filename>

quote MDTM <filename>.
This gives just the date and time and filesize but does not show the filename. Does not get the required file with date and time from remote server.

Well, Thank you and appreciate for all of your support. One of my friend has provided a solution in 'perl' which works as I needed. Posting the script for those who are in need of getting the date and time while doing FTP. This script can be run if you have perl installed. The script is as follows:

#!/usr/bin/perl
#
# file date modify
# 6/28/05
# ver 1.0.1
#

use Date::Manip;
use Net::FTP;

$sourcedir = "filepath";
$filename1 = "filename";
$login = "remote server userid";
$passw = "remote server password";
$server = "remote server name";

$ftp = Net::FTP-&gt;new\("$server"\);
$ftp-&gt;login\($login,$passw\);
$ftp-&gt;cwd\($sourcedir\);
@fileinfo = $ftp-&gt;dir\($filename1\);
$ftp-&gt;get\($filename1\);
$ftp-&gt;quit;

($accesstime, $modtime) = (stat($filename1))[8,9];

print $modtime . "\n";

$modtimeconv = localtime($modtime);

$datestr = UnixDate($modtimeconv, "%A, %B %e at %i:%M%p");

print "$datestr \n";

print $fileinfo[0] . "\n";

$dateinfo = substr($fileinfo[0], 45, 12);
print $dateinfo . "\n";

$finaldate = ParseDate($dateinfo);
$finaldate = $finaldate + 1;
$unixdate = UnixDate($finaldate,"%s");
print $unixdate . "\n";

utime($accesstime, $unixdate, $filename1);

#End of the perl script

:slight_smile: :slight_smile: :slight_smile:

The filename is already here. You can combine the filename and time in your script.