@Test(expected = BackgroundException.class) public void testSetTimestamp() throws Exception { final FTPWorkdirService workdir = new FTPWorkdirService(session); final Path home = workdir.find(); final long modified = System.currentTimeMillis(); final Path test = new Path(workdir.find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); new FTPTouchFeature(session).touch(test, new TransferStatus()); new FTPUTIMETimestampFeature(session).setTimestamp(test, modified); new FTPDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public void setTimestamp(final Path file, final TransferStatus status) 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().sendSiteCommand(String.format("UTIME %s %s %s %s UTC", file.getAbsolute(), formatter.format(new Date(System.currentTimeMillis()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), 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); } }
FTPUTIMETimestampFeature extends DefaultTimestampFeature implements Timestamp { @Override public void setTimestamp(final Path file, final TransferStatus status) 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().sendSiteCommand(String.format("UTIME %s %s %s %s UTC", file.getAbsolute(), formatter.format(new Date(System.currentTimeMillis()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), 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); } } }
FTPUTIMETimestampFeature extends DefaultTimestampFeature implements Timestamp { @Override public void setTimestamp(final Path file, final TransferStatus status) 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().sendSiteCommand(String.format("UTIME %s %s %s %s UTC", file.getAbsolute(), formatter.format(new Date(System.currentTimeMillis()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), 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); } } FTPUTIMETimestampFeature(final FTPSession session); }
FTPUTIMETimestampFeature extends DefaultTimestampFeature implements Timestamp { @Override public void setTimestamp(final Path file, final TransferStatus status) 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().sendSiteCommand(String.format("UTIME %s %s %s %s UTC", file.getAbsolute(), formatter.format(new Date(System.currentTimeMillis()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), 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); } } FTPUTIMETimestampFeature(final FTPSession session); @Override void setTimestamp(final Path file, final TransferStatus status); }
FTPUTIMETimestampFeature extends DefaultTimestampFeature implements Timestamp { @Override public void setTimestamp(final Path file, final TransferStatus status) 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().sendSiteCommand(String.format("UTIME %s %s %s %s UTC", file.getAbsolute(), formatter.format(new Date(System.currentTimeMillis()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), TimeZone.getTimeZone("UTC")), formatter.format(new Date(status.getTimestamp()), 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); } } FTPUTIMETimestampFeature(final FTPSession session); @Override void setTimestamp(final Path file, final TransferStatus status);  }