@Override public void setTimestamp(final Path file, final Long modified) throws BackgroundException { if(failure != null) { if(log.isDebugEnabled()) { log.debug(String.format("Skip setting timestamp for %s due to previous failure %s", file, failure.getMessage())); } throw new FTPExceptionMappingService().map("Cannot change timestamp of {0}", failure, file); } try { final MDTMSecondsDateFormatter formatter = new MDTMSecondsDateFormatter(); // The utime() function sets the access and modification times of the named // file from the structures in the argument array timep. // The access time is set to the value of the first element, // and the modification time is set to the value of the second element // Accessed date, modified date, created date if(!session.getClient().sendSiteCommand(String.format("UTIME %s %s %s %s UTC", file.getAbsolute(), formatter.format(new Date(System.currentTimeMillis()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(modified), TimeZone.getTimeZone("UTC")), formatter.format(new Date(modified), TimeZone.getTimeZone("UTC"))))) { throw failure = new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } } catch(IOException e) { throw new FTPExceptionMappingService().map("Cannot change timestamp of {0}", e, file); } } }
/** * Parse the timestamp using the MTDM format * * @param timestamp Date string * @return Milliseconds */ protected long parseTimestamp(final String timestamp) { if(null == timestamp) { return -1; } try { final Date parsed = new MDTMSecondsDateFormatter().parse(timestamp); return parsed.getTime(); } catch(InvalidDateException e) { log.warn("Failed to parse timestamp:" + e.getMessage()); try { final Date parsed = new MDTMMillisecondsDateFormatter().parse(timestamp); return parsed.getTime(); } catch(InvalidDateException f) { log.warn("Failed to parse timestamp:" + f.getMessage()); } } log.error(String.format("Failed to parse timestamp %s", timestamp)); return -1; }
@Override public void setTimestamp(final Path file, final Long modified) throws BackgroundException { if(failure != null) { if(log.isDebugEnabled()) { log.debug(String.format("Skip setting timestamp for %s due to previous failure %s", file, failure.getMessage())); } throw new FTPExceptionMappingService().map("Cannot change timestamp of {0}", failure, file); } try { final MDTMSecondsDateFormatter formatter = new MDTMSecondsDateFormatter(); if(!session.getClient().setModificationTime(file.getAbsolute(), formatter.format(modified, TimeZone.getTimeZone("UTC")))) { throw failure = new FTPException(session.getClient().getReplyCode(), session.getClient().getReplyString()); } } catch(IOException e) { throw new FTPExceptionMappingService().map("Cannot change timestamp of {0}", e, file); } } }