Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 25706 invoked from network); 12 Sep 2002 11:36:47 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 12 Sep 2002 11:36:47 -0000 Received: (qmail 24598 invoked by uid 97); 12 Sep 2002 11:37:17 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 24517 invoked by uid 97); 12 Sep 2002 11:37:16 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 24497 invoked by uid 98); 12 Sep 2002 11:37:15 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <5DDFCC127CEED211A27200105A9CAB7B0142D77C@S64P10BM756> From: EXT / FOCAL MALAPRADE Roland To: "'ant-dev@jakarta.apache.org'" Subject: FTP Optional task - try to change it to support "last modified da te" preservation Date: Thu, 12 Sep 2002 13:36:31 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Organization: S.N.C.F. French Railways X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi, I was using the task to retrieve files from a server, and I noticed that files' last modified date was not being preserved. I originally posted this problem to ant-user, but since I am trying to change the Ant code, I thought it would be more appropriate to post here. I added this code to FTP.java: /** Code added **/ private boolean preserveLastModified = true; public void setPreserveLastModified(boolean preserve) { this.preserveLastModified = preserve; } /** * Returns the timestamp of a remote file. * The timestamp is usually the file's last modified date. * @returns the timestamp as a long. */ protected long getFileTimestamp(FTPClient ftp, String remoteFile) throws IOException, BuildException { log("getting date for " + remoteFile, Project.MSG_VERBOSE); FTPFile[] files = ftp.listFiles(remoteFile); // For Microsoft's Ftp-Service an Array with length 0 is // returned if configured to return listings in "MS-DOS"-Format if (files == null || files.length == 0) { // If we are sending files, then assume out of date. // If we are getting files, then throw an error return 0L; } return files[0].getTimestamp().getTime().getTime(); } /** End code added **/ And I changed the getFile method to this (changes indicated) : /** Code changed **/ protected void getFile(FTPClient ftp, String dir, String filename) throws IOException, BuildException { OutputStream outstream = null; // getTimestamp() try { File file = project.resolveFile(new File(dir, filename).getPath()); if (newerOnly && isUpToDate(ftp, file, resolveFile(filename))) { return; } if (verbose) { log("transferring " + filename + " to " + file.getAbsolutePath()); } File pdir = fileUtils.getParentFile(file); if (!pdir.exists()) { pdir.mkdirs(); } outstream = new BufferedOutputStream(new FileOutputStream(file)); ftp.retrieveFile(resolveFile(filename), outstream); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { String s = "could not get file: " + ftp.getReplyString(); if (skipFailedTransfers == true) { log(s, Project.MSG_WARN); skipped++; } else { throw new BuildException(s); } } else { log("File " + file.getAbsolutePath() + " copied from " + server, Project.MSG_VERBOSE); transferred++; } /** My changes **/ if (preserveLastModified) { long l = getFileTimestamp(ftp,resolveFile(filename)); log("File's last modified date : " + new Date(l).toString() , Project.MSG_VERBOSE); if (l != 0L) { if (!file.setLastModified(l)) { log("local file's last modified date could not be set : " + file.getAbsolutePath() , Project.MSG_WARN); } } else { log("File's last modified date could not be preserved : " + file.getAbsolutePath() , Project.MSG_WARN); } } /** End my changes **/ } finally { if (outstream != null) { try { outstream.close(); } catch (IOException ex) { // ignore it } } } } /** End code changed **/ Now the problem is that the files' last modified date is not being changed. Is it something I am doing wrong? Is the file being modified after the call to the getFile() method ? (I looked but I couldn't find anything). Is it possible that you can't set the "last modified date" to a date earlier than the creation time ? (which is what I'm trying to do. I've looked on the net, but I haven't found anything stating that you can't.) BTW I am using: - Ant 1.5 (9 July 2002) - NetComponents 1.3.8a - JDK 1.3.1-b24 Any help would be great. Roland. -- To unsubscribe, e-mail: For additional commands, e-mail: