Пример #1
0
 /** Test attempt to change remote directory to a nonexistent directory. */
 @Test
 public void test05ChangeRemoteDirWithBadDirFails() throws Exception {
   session.login(USER, PASSWORD);
   String missingDir = "eleventy_squash";
   assertTrue(!session.changeWorkingDirectory(missingDir));
   assertTrue(!session.printWorkingDirectory().contains(missingDir));
 }
Пример #2
0
 /**
  * Tests sane default for local directory if directory no longer exists.
  *
  * @throws Exception
  */
 @Test
 public void test08RestoreCanRevertToDefaultLocalIfLocalDirIsRemoved() throws Exception {
   assertTrue(testDir.delete());
   session.disconnect();
   session.restore();
   assertTrue(session.getLocalDirectory().equals(System.getProperty("user.dir")));
 }
Пример #3
0
 /**
  * Tests restoring session after disconnect.
  *
  * @throws Exception
  */
 @Test
 public void test07CanRestoreSessionAfterDisconnect() throws Exception {
   session.disconnect();
   session.restore();
   assertTrue(session.isConnected());
   assertTrue(session.printWorkingDirectory().contains("for_testing"));
 }
Пример #4
0
    /**
     * Tests creating file in appropriate local directory.
     *
     * @throws Exception unexpected
     */
    @Test
    public void test04CanCreateFileInNewLocalDirectory() throws Exception {
      session.changeLocalDirectory(System.getProperty("user.dir"));
      testDir = new File(session.getLocalDirectory(), "goodSessionTestDir");
      testDir.mkdir();
      testDir.deleteOnExit();
      session.changeLocalDirectory(testDir.getPath());

      File testfile = new File(session.getLocalDirectory(), "goodSessionTest04");
      testfile.createNewFile();
      testfile.deleteOnExit();
      assertTrue(testfile.getAbsolutePath().contains(testDir.getAbsolutePath()));
      // Force deletion now so we can delete containing directory later.
      assertTrue(testfile.delete());
    }
Пример #5
0
  public SecureFTPError doIt() throws CommandException {
    SecureFTPError result = super.doIt();

    FTPSession session = SecureFTP.getFTPSession();
    PrintStream out = session.getPrintStream();

    if (!displayedWarning) {
      displayedWarning = true;

      if (session.isInteractiveOn()) {
        if (!CLIUtil.yesNoPrompt(
            "You are about to permenently delete " + "multiple files. Continue?")) {
          out.println("Local files deletion aborted.");
          return result;
        }
      }
    }

    for (int i = 0; i < getArgs().size(); i++) {
      File currentFile = session.getLocalDir();

      String newFileStr = (String) getArgs().get(i);
      File newFile = new File(newFileStr);

      if (!newFile.isAbsolute()) {
        currentFile = new File(currentFile, newFileStr);
      } else {
        currentFile = newFile;
      }

      // resend items that have patterns in them
      if (session.isGlobOn() && !currentFile.exists()) {
        try {
          File[] fileGlob =
              CLIUtil.globLocalPathForFiles(currentFile.getAbsolutePath(), CLIUtil.GLOB_ALL_FILES);

          if (fileGlob.length == 0) {
            out.println("File and/or directory not found.");
            result.setCode(SecureFTPError.NO_SUCH_FILE);
            return result;
          }

          ArrayList globList = new ArrayList(fileGlob.length);
          for (int j = 0; j < fileGlob.length; j++) {
            globList.add(fileGlob[j].getAbsolutePath());
          }

          LMDeleteCommand cmd = new LMDeleteCommand(true);
          cmd.setArgs(globList);
          result = SecureFTP.getCommandDispatcher().fireCommand(this, cmd);
          if (SecureFTPError.PERMISSION_DENIED == result.getCode()) {
            break;
          }

          continue;
        } catch (FileNotFoundException fne) {
        }
      }

      if (!currentFile.exists()) {
        out.println("File and/or directory does not exist.");
        result.setCode(SecureFTPError.NO_SUCH_FILE);
      }

      // at this point we should have a valid file/directory
      else if (currentFile.isDirectory()) {
        File[] files = currentFile.listFiles();
        if (files == null) {
          out.println("Permission denied: Deletion of \"" + currentFile.getName() + "\" failed.");
          continue;
        } else {
          ArrayList list = new ArrayList(files.length);
          for (int k = 0; k < files.length; k++) {
            list.add(files[k].getAbsolutePath());
          }
          LMDeleteCommand cmd = new LMDeleteCommand(true);
          cmd.setArgs(list);
          result = SecureFTP.getCommandDispatcher().fireCommand(this, cmd);
          if (SecureFTPError.PERMISSION_DENIED == result.getCode()) {
            break;
          }

          LRmDirCommand rmCmd = new LRmDirCommand();
          ArrayList args = new ArrayList(1);
          args.add(currentFile.getAbsolutePath());
          rmCmd.setArgs(args);
          result = SecureFTP.getCommandDispatcher().fireCommand(this, rmCmd);
        }
      } else {
        LDeleteCommand ldc = new LDeleteCommand();
        ArrayList args = new ArrayList(1);
        args.add(currentFile.getAbsolutePath());
        ldc.setArgs(args);

        result = SecureFTP.getCommandDispatcher().fireCommand(this, ldc);

        if (SecureFTPError.PERMISSION_DENIED == result.getCode()) {
          out.println("Permission denied: Deletion of \"" + currentFile.getName() + "\" failed.");
          result.setCode(SecureFTPError.PERMISSION_DENIED);
          return result;
        }
      }
    }

    return result;
  }
Пример #6
0
 /** Tests changing local directory. */
 @Test
 public void test03CanChangeLocalDirectory() {
   assertTrue(session.changeLocalDirectory(folder.getRoot().getPath()));
 }
Пример #7
0
 /**
  * Tests login functionality.
  *
  * @throws Exception unexpected
  */
 @Test
 public void test02CanLogin() throws Exception {
   assertTrue(session.login(USER, PASSWORD));
   session.enterLocalPassiveMode();
   session.setFileType(FTP.BINARY_FILE_TYPE);
 }
Пример #8
0
 /**
  * Tests connection functionality.
  *
  * @throws Exception unexpected
  */
 @Test
 public void test01CanConnect() throws Exception {
   session.connect(HOST, PORT);
   assertTrue(session.isConnected());
 }
Пример #9
0
 @AfterClass
 public static void teardown() throws Exception {
   session.disconnect();
 }
Пример #10
0
 /** Test attempt to login with bad credentials. */
 @Test
 public void test04LoginWithBadCredentialsFails() throws Exception {
   session.connect(HOST, PORT);
   assertTrue(!session.login("failtestuser", PASSWORD));
   assertTrue(!session.login(USER, "badpass"));
 }
Пример #11
0
 /** Test attempt to login without a connection. */
 @Test(expected = IOException.class)
 public void test03LoginWithoutConnectThrowsException() throws Exception {
   session.login(USER, PASSWORD);
 }
Пример #12
0
 /** Test handling of bad port. */
 @Test(expected = IOException.class)
 public void test02ConnectWithBadPortThrowsException() throws Exception {
   session.connect(HOST, 12345);
 }
Пример #13
0
 /** Test handling of bad host. */
 @Test(expected = IOException.class)
 public void test01ConnectWithBadHostThrowsException() throws Exception {
   session.connect("banana", PORT);
 }
Пример #14
0
 /**
  * Tests changing remote directory.
  *
  * @throws Exception
  */
 @Test
 public void test06CanChangeRemoteDirectory() throws Exception {
   assertTrue(session.changeWorkingDirectory("for_testing"));
   assertTrue(session.printWorkingDirectory().contains("for_testing"));
 }