Examples of SFTPv3Client


Examples of ch.ethz.ssh2.SFTPv3Client

    }
  }

  private SFTPv3Client FtpClient() throws Exception {
    if (sftpClient == null) {
      sftpClient = new SFTPv3Client(this.getSshConnection());
    }
    return sftpClient;
  }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

  }

  public File transferCommandScript(File commandFile, boolean isWindows) throws Exception {
    try {
      SFTPv3Client sftpClient = new SFTPv3Client(this.getSshConnection());
      SFTPv3FileAttributes attr = new SFTPv3FileAttributes();
      attr.permissions = new Integer(0700);

      boolean exists = true;
      // check if File already exists
      while (exists) {
        try {
          SFTPv3FileAttributes attribs = sftpClient.stat(commandFile.getName());
        }
        catch (SFTPException e) {
          getLogger().debug9("Error code when checking file existence: " + e.getServerErrorCode());
          exists = false;
        }
        if (exists) {
          getLogger().debug1("file with that name already exists, trying new name...");
          String suffix = (isWindows ? ".cmd" : ".sh");
          File resultFile = File.createTempFile("sos", suffix);
          resultFile.delete();
          commandFile.renameTo(resultFile);
          commandFile = resultFile;
        }
      }

      // set execute permissions for owner
      SFTPv3FileHandle fileHandle = sftpClient.createFileTruncate(commandFile.getName(), attr);

      FileInputStream fis = null;
      long offset = 0;
      try {
        fis = new FileInputStream(commandFile);
        byte[] buffer = new byte[1024];
        while (true) {
          int len = fis.read(buffer, 0, buffer.length);
          if (len <= 0)
            break;
          sftpClient.write(fileHandle, offset, buffer, 0, len);
          offset += len;
        }
        fis.close();
        fis = null;

      }
      catch (Exception e) {
        throw new Exception("error occurred writing file [" + commandFile.getName() + "]: " + e.getMessage());
      }
      finally {
        if (fis != null)
          try {
            fis.close();
            fis = null;
          }
          catch (Exception ex) {
          } // gracefully ignore this error
      }
      sftpClient.closeFile(fileHandle);

      fileHandle = null;
      sftpClient.close();
      return commandFile;
    }
    catch (Exception e) {
      throw new Exception("Error transferring command script: " + e, e);
    }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

    }
  }

  private void deleteCommandScript(String commandFile) throws Exception {
    try {
      SFTPv3Client sftpClient = new SFTPv3Client(this.getSshConnection());
      sftpClient.rm(commandFile);
      sftpClient.close();
    }
    catch (Exception e) {
      getLogger().warn("Failed to delete remote command script: " + e);
    }
  }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

    }
  }

  private SFTPv3Client FtpClient() throws Exception {
    if (sftpClient == null) {
      sftpClient = new SFTPv3Client(this.getSshConnection());
    }
    return sftpClient;
  }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

            if (!isAuthenticated) throw new Exception("authentication failed [host=" + this.getHost() + ", port=" + this.getPort() + ", user:" + this.getUser()
                    + ", auth_method=" + this.getAuthenticationMethod() + ", auth_file=" + this.getAuthenticationFilename());

           
            sftpClient = new SFTPv3Client(sshConnection);
            connected = true;
            reply = "OK";
        } catch (Exception e) {
          reply = e.toString();
            if (sshConnection != null) try { disconnect(); } catch (Exception ex) {} // gracefully ignore this error
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

  }

  private SFTPv3Client Client() {
    if (objFTPClient == null) {
      try {
        objFTPClient = new SFTPv3Client(sshConnection);
      }
      catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

   *
   * @see jSimMacs.logic.location.DataHandler#createDirectory(java.lang.String, boolean)
   */
  public boolean createDirectory(String dir, boolean absolutePath) throws IOException {
    boolean success = true;
    SFTPv3Client sftpConn = null;
    String directory = dir;
    if(!absolutePath)
      directory = rProject.getPath() + dir;
    try {

      sftpConn = new SFTPv3Client(conn);
      boolean createDir = true;
      try {
        sftpConn.lstat(directory);
        createDir = false;
      } catch (IOException e) {
        createDir = true;
      }
      if (createDir)
        sftpConn.mkdir(directory, standardPermission);
    } catch (IOException e) {
      success = false;
      throw e;
    } finally {
      if (sftpConn != null)
        sftpConn.close();
    }
    return success;
  }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

   * @throws IOException
   */
  public SFTPv3DirectoryEntry getDirectoryEntry(String path)
      throws IOException {
    SFTPv3DirectoryEntry entry = new SFTPv3DirectoryEntry();
    SFTPv3Client sftpConn = null;
    try {
      sftpConn = new SFTPv3Client(conn);
      SFTPv3FileAttributes attribute = sftpConn.lstat(path);
      entry.attributes = attribute;
      entry.filename = path.substring(path.lastIndexOf("/") + 1);
    } catch (IOException e) {
      throw e;
    } finally {
      if (sftpConn != null)
        sftpConn.close();
    }
    return entry;
  }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

   *
   * @see jSimMacs.logic.location.DataHandler#createFile(java.lang.String)
   */
  public boolean createFile(String fileDirectory) throws IOException {
    boolean success = true;
    SFTPv3Client sftpConn = null;
    try {
      sftpConn = new SFTPv3Client(conn);
      sftpConn.createFile(fileDirectory);
    } catch (IOException e) {
      success = false;
      throw new IOException();
    } finally {
      if (sftpConn != null)
        sftpConn.close();
    }
    return success;
  }
View Full Code Here

Examples of com.trilead.ssh2.SFTPv3Client

   * @return Vector of DirectoryEntries
   * @throws IOException
   */
  public Vector<SFTPv3DirectoryEntry> listFiles(String path)
      throws IOException {
    SFTPv3Client sftpConn = null;
    Vector<SFTPv3DirectoryEntry> nodes;
    try {
      sftpConn = new SFTPv3Client(conn);
      nodes = sftpConn.ls(path);
      filterNodes(nodes);
    } catch (IOException e) {
      throw e;
    } finally {
      if (sftpConn != null)
        sftpConn.close();
    }
    return nodes;

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.