Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / source / ch / cyberduck / core / ftp / FTPMFMTTimestampFeature.java
blobec2d4ca33fcbec892cabaa450ef69e79a438d6f8
1 package ch.cyberduck.core.ftp;
3 /*
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
20 import ch.cyberduck.core.Path;
21 import ch.cyberduck.core.date.MDTMSecondsDateFormatter;
22 import ch.cyberduck.core.exception.BackgroundException;
23 import ch.cyberduck.core.features.Timestamp;
25 import org.apache.log4j.Logger;
27 import java.io.IOException;
28 import java.util.TimeZone;
30 /**
31 * @version $Id$
33 public class FTPMFMTTimestampFeature implements Timestamp {
34 private static final Logger log = Logger.getLogger(FTPMFMTTimestampFeature.class);
36 private FTPSession session;
38 private FTPException failure;
40 public FTPMFMTTimestampFeature(final FTPSession session) {
41 this.session = session;
44 @Override
45 public void setTimestamp(final Path file, final Long modified) throws BackgroundException {
46 if(failure != null) {
47 if(log.isDebugEnabled()) {
48 log.debug(String.format("Skip setting timestamp for %s due to previous failure %s", file, failure.getMessage()));
50 throw new FTPExceptionMappingService().map("Cannot change timestamp of {0}", failure, file);
52 try {
53 final MDTMSecondsDateFormatter formatter = new MDTMSecondsDateFormatter();
54 if(!session.getClient().setModificationTime(file.getAbsolute(),
55 formatter.format(modified, TimeZone.getTimeZone("UTC")))) {
56 throw failure = new FTPException(session.getClient().getReplyCode(),
57 session.getClient().getReplyString());
60 catch(IOException e) {
61 throw new FTPExceptionMappingService().map("Cannot change timestamp of {0}", e, file);