예제 #1
0
  /* (non-Javadoc)
   * @see net.sf.thingamablog.transport.PublishTransport#publishFile(java.lang.String, java.io.File, net.sf.thingamablog.transport.TransportProgress)
   */
  public boolean publishFile(String pubPath, File file, TransportProgress tp) {
    if (sftp == null) {
      failMsg = "SFTP Client not initialized!";
      return false;
    }

    if (!isConnected()) {
      failMsg = "Not Connected!!!";
      return false;
    }

    if (tp.isAborted()) {
      failMsg = "Aborted";
      return false;
    }

    if (!pubPath.endsWith("/")) pubPath += "/"; // append a trailing slash if needed

    try {
      String cwd = sftp.pwd();
      if (!cwd.endsWith("/")) cwd += "/";
      if (!pubPath.equals(cwd)) {
        boolean changedDir = false;
        try {
          sftp.cd(pubPath); // try to change to the pub path
          changedDir = true; // changed dir OK
          System.out.println("Changed to " + pubPath);
        } catch (Exception cdEx) {
          logger.log(Level.WARNING, "Problem changing SFTP dir", cdEx);
        }

        if (!changedDir) {
          // was unable to change dir. the dir likely does not exist
          // so we'll try making the dir structure of pubPath
          mkdirs(pubPath);
          // sftp.cd(pubPath);
        }
      }

      int mode = ChannelSftp.OVERWRITE;
      // String dest = pubPath + file.getName();
      InputStream is = new FileInputStream(file);
      sftp.put(is, file.getName(), new MyProgressMonitor(tp), mode);
      is.close();

      return true;
    } catch (Exception ex) {
      failMsg = "Error publishing file to " + pubPath;
      failMsg += "\n" + ex.getMessage();
      logger.log(Level.WARNING, failMsg, ex);
      ex.printStackTrace();
    }

    return false;
  }
예제 #2
0
 public boolean count(long count) {
   progress.bytesTransferred(count);
   return !progress.isAborted();
 }