diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-12-14 15:18:37 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-12-14 15:18:37 +0000 |
commit | 26a8e37fdcab433c8e623b29fb35c0907b2a05de (patch) | |
tree | 9228e612a67095337200051b47b0f14c99485ac8 /ftp.c | |
parent | [w3m-dev 03567] default keybinding (diff) | |
download | w3m-26a8e37fdcab433c8e623b29fb35c0907b2a05de.tar.gz w3m-26a8e37fdcab433c8e623b29fb35c0907b2a05de.zip |
[w3m-dev 03568] Re: preserve timestamp
* etc.c (USE_COOKIE): moved
* file.c (utime.h): include
(setModtime): added
(loadGeneralFile): set f.modtime
(_doFileCopy): setModtime()
(doFileSave): setModtime()
* ftp.c (getFtpModtime): added
(openFTP): pass URLFile, set modtime
* html.h (URLFile): add modtime
* proto.h (openFTP): arg URLFile *uf
(mymktime): always
* url.c (init_stream): initialize modtime
(openFTPStream): pass URLFile
(openURL): openFTPStream
From: Takahashi Youichirou <nikuq@hk.airnet.ne.jp>
Diffstat (limited to '')
-rw-r--r-- | ftp.c | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -1,4 +1,4 @@ -/* $Id: ftp.c,v 1.15 2002/11/18 18:26:13 ukai Exp $ */ +/* $Id: ftp.c,v 1.16 2002/12/14 15:18:38 ukai Exp $ */ #include <stdio.h> #include <pwd.h> #include <Str.h> @@ -351,6 +351,34 @@ FtpData(FTP ftp, char *cmd, char *arg, char *mode) return FtpDataBody(ftp, cmd, arg, mode); } +time_t +getFtpModtime(FTP ftp, char *path) +{ + Str tmp; + char *p; + struct tm tm; + time_t t; + + memset(&tm, 0, sizeof(struct tm)); + tmp = Sprintf("MDTM %s\r\n", path); + fwrite(tmp->ptr, tmp->length, sizeof(char), ftp->wcontrol); + fflush(ftp->wcontrol); + tmp = read_response(ftp); + if (atoi(tmp->ptr) != 213) + return -1; + for (p = tmp->ptr + 4; *p && *p == ' '; p++) + ; + if (sscanf(p, "%04d%02d%02d%02d%02d%02d", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 6) + return -1; + tm.tm_year -= 1900; + tm.tm_mon--; + t = mktime(&tm); + t += mktime(localtime(&t)) - mktime(gmtime(&t)); + return t; +} + int FtpClose(FTP ftp) { @@ -394,7 +422,7 @@ static int ftp_system(FTP); #define FTPDIR_FILE 3 FILE * -openFTP(ParsedURL *pu) +openFTP(ParsedURL *pu, URLFile *uf) { Str tmp2 = Strnew(); Str tmp3 = Strnew(); @@ -472,6 +500,7 @@ openFTP(ParsedURL *pu) goto ftp_dir; /* Get file */ + uf->modtime = getFtpModtime(current_ftp, realpathname); FtpBinary(current_ftp); if (ftp_pasv(current_ftp) < 0) { FtpBye(current_ftp); |