Beispiel #1
0
 /** Copy a local file to a remote file. Default option 'overwrite' */
 public void putFile(
     FileFragment local, FileFragment remote, final ProgressMonitor progressMonitor)
     throws FileResourceException {
   if (local.isFragment() || remote.isFragment()) {
     throw new UnsupportedOperationException(
         "The FTP provider does not support partial transfers");
   }
   String currentDirectory = getCurrentDirectory();
   File localFile = new File(local.getFile());
   try {
     ftpClient.setPassive();
     ftpClient.setLocalActive();
     final long size = localFile.length();
     DataSource source;
     if (progressMonitor != null) {
       source =
           new DataSourceStream(new FileInputStream(localFile)) {
             public Buffer read() throws IOException {
               progressMonitor.progress(totalRead, size);
               return super.read();
             }
           };
     } else {
       source = new DataSourceStream(new FileInputStream(localFile));
     }
     ftpClient.put(remote.getFile(), source, null, false);
   } catch (Exception e) {
     throw translateException("Cannot transfer the given file", e);
   }
 }
Beispiel #2
0
 /** Equivalent to cp/copy command */
 public void getFile(
     FileFragment remote, FileFragment local, final ProgressMonitor progressMonitor)
     throws FileResourceException {
   if (remote.isFragment() || local.isFragment()) {
     throw new UnsupportedOperationException(
         "The FTP provider does not support partial transfers");
   }
   String currentDirectory = getCurrentDirectory();
   File localFile = new File(local.getFile());
   try {
     ftpClient.setPassive();
     ftpClient.setLocalActive();
     final long size = localFile.length();
     DataSink sink;
     if (progressMonitor != null) {
       // The sink is used to follow progress
       sink =
           new DataSinkStream(new FileOutputStream(localFile)) {
             public void write(Buffer buffer) throws IOException {
               super.write(buffer);
               progressMonitor.progress(offset, size);
             }
           };
     } else {
       sink = new DataSinkStream(new FileOutputStream(localFile));
     }
     ftpClient.get(remote.getFile(), sink, null);
   } catch (Exception e) {
     throw translateException("Cannot retrieve the given file", e);
   }
 }