/**
  * Fetch the needed file information for a given file (size, last modification time) and report it
  * back in a SshResource
  *
  * @param source ssh uri for the file to get info for
  * @return SshResource filled with the needed informations
  * @see org.apache.ivy.plugins.repository.Repository#getResource(java.lang.String)
  */
 public SshResource resolveResource(String source) {
   Message.debug("SShRepository:resolveResource called: " + source);
   SshResource result = null;
   Session session = null;
   try {
     session = getSession(source);
     Scp myCopy = new Scp(session);
     Scp.FileInfo fileInfo = myCopy.getFileinfo(new URI(source).getPath());
     result =
         new SshResource(this, source, true, fileInfo.getLength(), fileInfo.getLastModified());
   } catch (IOException e) {
     if (session != null) {
       releaseSession(session, source);
     }
     result = new SshResource();
   } catch (URISyntaxException e) {
     if (session != null) {
       releaseSession(session, source);
     }
     result = new SshResource();
   } catch (RemoteScpException e) {
     result = new SshResource();
   }
   Message.debug("SShRepository:resolveResource end.");
   return result;
 }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.ivy.repository.Repository#get(java.lang.String, java.io.File)
   */
  public void get(String source, File destination) throws IOException {
    Message.debug("SShRepository:get called: " + source + " to " + destination.getCanonicalPath());
    if (destination.getParentFile() != null) {
      destination.getParentFile().mkdirs();
    }
    Session session = getSession(source);

    URI sourceUri = null;
    try {
      sourceUri = new URI(source);
    } catch (URISyntaxException e) {
      IOException ioe = new IOException("The uri '" + source + "' is not valid!");
      ioe.initCause(e);
      throw ioe;
    }

    try {
      Scp myCopy = new Scp(session);
      myCopy.get(sourceUri.getPath(), destination.getCanonicalPath());
    } catch (IOException e) {
      if (session != null) {
        releaseSession(session, source);
      }
      throw e;
    } catch (RemoteScpException e) {
      throw new IOException(e.getMessage());
    }
  }
 /**
  * Not really streaming...need to implement a proper streaming approach?
  *
  * @param resource to stream
  * @return InputStream of the resource data
  */
 public InputStream openStream(SshResource resource) throws IOException {
   Session session = getSession(resource.getName());
   Scp scp = new Scp(session);
   ByteArrayOutputStream os = new ByteArrayOutputStream();
   try {
     scp.get(resource.getName(), os);
   } catch (IOException e) {
     if (session != null) {
       releaseSession(session, resource.getName());
     }
     throw e;
   } catch (RemoteScpException e) {
     throw new IOException(e.getMessage());
   }
   return new ByteArrayInputStream(os.toByteArray());
 }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.ivy.repository.Repository#put(java.io.File, java.lang.String, boolean)
   */
  public void put(File source, String destination, boolean overwrite) throws IOException {
    Message.debug("SShRepository:put called: " + destination);
    Session session = getSession(destination);

    URI destinationUri = null;
    try {
      destinationUri = new URI(destination);
    } catch (URISyntaxException e) {
      IOException ioe = new IOException("The uri '" + destination + "' is not valid!");
      ioe.initCause(e);
      throw ioe;
    }

    try {
      String filePath = destinationUri.getPath();
      int lastSep = filePath.lastIndexOf(fileSeparator);
      String path;
      String name;
      if (lastSep == -1) {
        name = filePath;
        path = null;
      } else {
        name = filePath.substring(lastSep + 1);
        path = filePath.substring(0, lastSep);
      }
      if (!overwrite) {
        if (checkExistence(filePath, session)) {
          throw new IOException("destination file exists and overwrite == false");
        }
      }
      if (path != null) {
        makePath(path, session);
      }
      Scp myCopy = new Scp(session);
      myCopy.put(source.getCanonicalPath(), path, name, publishPermissions);
    } catch (IOException e) {
      if (session != null) {
        releaseSession(session, destination);
      }
      throw e;
    } catch (RemoteScpException e) {
      throw new IOException(e.getMessage());
    }
  }