コード例 #1
0
  public static void main(String[] args) throws IOException {
    ConnectionOptions options = new ConnectionOptions();
    options.set(ADDRESS, "unix-box");
    options.set(USERNAME, "demo");
    options.set(PASSWORD, "secret");
    options.set(OPERATING_SYSTEM, UNIX);
    options.set(CONNECTION_TYPE, SFTP);
    OverthereConnection connection = Overthere.getConnection("ssh", options);
    try {
      connection.execute(CmdLine.build("cp", "-r", "/var/log/apt", "/tmp/logs1"));
      OverthereFile logs1 = connection.getFile("/tmp/logs1");
      OverthereFile logs2 = connection.getFile("/tmp/logs2");
      logs2.delete();

      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());

      logs1.renameTo(logs2);
      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());

      logs2.copyTo(logs1);
      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());

      logs1.deleteRecursively();
      logs2.deleteRecursively();
      System.err.println("Exists #1: " + logs1.exists());
      System.err.println("Exists #2: " + logs2.exists());
    } finally {
      connection.close();
    }
  }
コード例 #2
0
 @Test
 @Assumption(methods = {"notLocal", "notCifs", "withPassword"})
 public void shouldNotConnectWithIncorrectPassword() {
   ConnectionOptions incorrectPasswordOptions = new ConnectionOptions(options);
   incorrectPasswordOptions.set(PASSWORD, "an-incorrect-password");
   try {
     Overthere.getConnection(protocol, incorrectPasswordOptions);
     fail("Expected not to be able to connect with an incorrect password");
   } catch (RuntimeIOException expected) {
   }
 }
コード例 #3
0
 @Test
 @Assumption(methods = {"notLocal", "notCifs"})
 public void shouldNotConnectWithIncorrectUsername() {
   ConnectionOptions incorrectUserNameOptions = new ConnectionOptions(options);
   incorrectUserNameOptions.set(USERNAME, "an-incorrect-username");
   try {
     Overthere.getConnection(protocol, incorrectUserNameOptions);
     fail("Expected not to be able to connect with an incorrect username");
   } catch (RuntimeIOException expected) {
   }
 }