Examples of FtpClientSession


Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

   public void testREST() throws Exception
   {
      Log log = getLogger(FtpConst.Commands.CMD_REST);
      log.info("Test...");

      FtpClientSession client = FtpTestConfig.getTestFtpClient();
      client.connect();

      assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser("admin")));
      assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new CmdPass("admin")));
      assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
      assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

      assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new CmdRest(9)));

      CmdRetr cmdRetr = new CmdRetr("/production/test_file.txt");
      assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));

      byte[] fileContent = cmdRetr.getFileContent();
      assertEquals(fileContent.length, FILE_CONTENT.length() - 9);

      for (int i = 0; i < fileContent.length; i++)
      {
         if (fileContent[i] != FILE_CONTENT.charAt(i + 9))
         {
            fail();
         }
      }

      client.close();

      log.info("Complete.");
   }
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

   public void testDELE() throws Exception
   {
      Log log = getLogger(FtpConst.Commands.CMD_DELE);
      log.info("Test...");

      FtpClientSession client = FtpTestConfig.getTestFtpClient();
      client.connect();

      assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser("admin")));
      assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new CmdPass("admin")));
      assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdDele("/production/test_file.txt")));

      client.close();

      log.info("Complete.");
   }
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

   public void testREST_STOR() throws Exception
   {
      Log log = getLogger("REST_STOR");
      log.info("Test...");

      FtpClientSession client = FtpTestConfig.getTestFtpClient();
      client.connect();

      assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser("admin")));
      assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new CmdPass("admin")));
      assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));

      String fileName = "/production/resr_test_file.txt";
      assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

      byte[] data = getBytes("DATABYTES");

      CmdStor cmdStor = new CmdStor(fileName);
      cmdStor.setFileContent(data);

      assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));

      assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

      CmdRetr cmdRetr = new CmdRetr(fileName);
      assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));

      byte[] dataAfter = cmdRetr.getFileContent();
      for (int i = 0; i < dataAfter.length; i++)
      {
         if (dataAfter[i] != data[i])
         {
            fail();
         }
      }

      assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

      assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new CmdRest(data.length)));

      byte[] secondData = getBytes("_APPENDED");

      cmdStor = new CmdStor(fileName);
      cmdStor.setFileContent(secondData);

      assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));

      assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

      cmdRetr = new CmdRetr(fileName);
      assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));

      String secondString = "DATABYTES_APPENDED";

      byte[] secondDataAfter = cmdRetr.getFileContent();
      for (int i = 0; i < secondDataAfter.length; i++)
      {
         if (secondDataAfter[i] != (byte)secondString.charAt(i))
         {
            fail();
         }
      }

      assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

      assertEquals(FtpConst.Replyes.REPLY_350, client.executeCommand(new CmdRest(4)));

      byte[] replasedData = getBytes("INT");

      cmdStor = new CmdStor(fileName);
      cmdStor.setFileContent(replasedData);

      assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));

      assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

      cmdRetr = new CmdRetr(fileName);
      assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdRetr));

      String readyString = "DATAINTES_APPENDED";

      byte[] readyBytes = cmdRetr.getFileContent();
      for (int i = 0; i < readyBytes.length; i++)
      {
         if (readyBytes[i] != (byte)readyString.charAt(i))
         {
            fail();
         }
      }

      assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdDele(fileName)));

      client.close();

      log.info("Complete.");
   }
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

      protected void createFolders(String rootTestFolder)
      {
         try
         {
            FtpClientSession client = FtpTestConfig.getTestFtpClient();
            client.connect();

            assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser(FtpTestConfig.USER_ID)));
            assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new CmdPass(FtpTestConfig.USER_PASS)));

            assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
            assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new CmdType("A")));

            assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

            log.info("Verify folder exists...");

            if (client.executeCommand(new CmdList(rootTestFolder)) == FtpConst.Replyes.REPLY_226)
            {
               log.info("Test folder exist. try delete it...");
               assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdRmd(rootTestFolder)));
               log.info("Deleted.");
            }

            for (int i1 = 1; i1 <= ITEMS_COUNT; i1++)
            {
               String folder1 = rootTestFolder + "/folder_" + i1;
               assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new CmdMkd(folder1)));
               for (int i2 = 1; i2 <= ITEMS_COUNT; i2++)
               {
                  String folder2 = folder1.substring(0);
                  folder2 += "/subfolder_" + i2;
                  assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new CmdMkd(folder2)));

                  for (int i3 = 0; i3 < ITEMS_COUNT; i3++)
                  {

                     assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

                     String file3 = folder2.substring(0);
                     file3 += "/test_file_" + i3 + ".txt";

                     CmdStor cmdStor = new CmdStor(file3);

                     byte[] fileData = new byte[256 * 4];
                     for (int c = 0; c < 256 * 4; c++)
                     {
                        fileData[c] = (byte)'A';
                        fileData[c] = fileData[c] += (byte)i3;
                     }

                     cmdStor.setFileContent(fileData);
                     assertEquals(FtpConst.Replyes.REPLY_226, client.executeCommand(cmdStor));

                     log.info("File [" + file3 + "] created");

                  }

               }
            }

            client.close();
         }
         catch (Exception exc)
         {
            log.info("Unhandled exception. " + exc.getMessage(), exc);
         }
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

      public void readAllFolders(String rootTestFolder)
      {
         try
         {
            FtpClientSession client = new FtpClientSessionImpl("127.0.0.1", 21);
            client.connect();

            assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser("admin")));
            assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new CmdPass("admin")));

            assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
            assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new CmdType("A")));

            for (int i1 = 1; i1 <= ITEMS_COUNT; i1++)
            {
               String folder1 = rootTestFolder + "/folder_" + i1;
               for (int i2 = 1; i2 <= ITEMS_COUNT; i2++)
               {
                  String folder2 = folder1.substring(0);
                  folder2 += "/subfolder_" + i2;
                  for (int i3 = 0; i3 < ITEMS_COUNT; i3++)
                  {
                     String file3 = folder2.substring(0);
                     file3 += "/test_file_" + i3 + ".txt";

                     log.info("CurFileName - [" + file3 + "]");

                     assertEquals(FtpConst.Replyes.REPLY_227, client.executeCommand(new CmdPasv()));

                     CmdRetr cmdRetr = new CmdRetr(file3);
                     int reply = client.executeCommand(cmdRetr);

                     log.info("RETR REPLY - " + reply);

                  }

               }

            }

            client.close();

         }
         catch (Exception exc)
         {
            log.info("Unhandled exception. " + exc.getMessage(), exc);
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

   public void testSingleThread() throws Exception
   {
      log.info("testSingleThread...");

      {
         FtpClientSession client = new FtpClientSessionImpl(FtpTestConfig.FTP_HOST, FtpTestConfig.FTP_PORT);
         client.connect();

         {
            CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
            assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
         }

         {
            CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
            assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
         }

         {
            CmdSyst cmdSyst = new CmdSyst();
            assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(cmdSyst));
         }

         {
            CmdCwd cmdCwd = new CmdCwd(FtpTestConfig.TEST_FOLDER);
            if (FtpConst.Replyes.REPLY_550 == client.executeCommand(cmdCwd))
            {
               CmdMkd cmdMkd = new CmdMkd(FtpTestConfig.TEST_FOLDER);
               assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(cmdMkd));

               cmdCwd = new CmdCwd(FtpTestConfig.TEST_FOLDER);
               assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(cmdCwd));
            }

            for (int i1 = 0; i1 < 10; i1++)
            {

               String folderName = FtpTestConfig.TEST_FOLDER + "/" + i1;
               assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new CmdMkd(folderName)));

               for (int i2 = 0; i2 < 10; i2++)
               {
                  String testSubFolder = folderName + "/" + i2;
                  assertEquals(FtpConst.Replyes.REPLY_257, client.executeCommand(new CmdMkd(testSubFolder)));
               }

            }
         }

         client.close();
      }

      HashMap<Integer, TestAgent> clients = new HashMap<Integer, TestAgent>();
      int count = 0;

      Random random = new Random();

      while (count < FtpTestConfig.CLIENTS_COUNT)
      {
         int nextId = random.nextInt(Integer.MAX_VALUE);
         log.info("NEXT ID: [" + nextId + "]");

         if (nextId < 10000)
         {
            continue;
         }

         Integer curInteger = new Integer(nextId);
         if (clients.containsKey(curInteger))
         {
            continue;
         }

         TestAgent testAgent = new TestAgent(curInteger, FtpTestConfig.CLIENT_DEPTH);
         clients.put(curInteger, testAgent);
         count++;
      }

      log.info("CLIENTS: [" + clients.size() + "]");

      Thread.sleep(3000);
      log.info("START ALL!!!!!!!!!!!!!!!!!!!!!!!!");
      IsNeedWaitAll = false;
      Thread.sleep(3000);

      {
         boolean alive = true;

         while (alive)
         {
            alive = false;
            Thread.sleep(2000);

            int live = 0;

            Iterator<Integer> keyIter = clients.keySet().iterator();
            while (keyIter.hasNext())
            {
               Integer agentKey = keyIter.next();
               TestAgent agent = clients.get(agentKey);
               if (agent.isAlive())
               {
                  alive = true;
                  live++;
               }
            }

            log.info(">>>>>>>>>>>>> LIVE: [" + live + "]");

         }
      }

      {
         {
            FtpClientSession client = new FtpClientSessionImpl(FtpTestConfig.FTP_HOST, FtpTestConfig.FTP_PORT);
            client.connect();

            {
               CmdUser cmdUser = new CmdUser(FtpTestConfig.USER_ID);
               assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(cmdUser));
            }

            {
               CmdPass cmdPass = new CmdPass(FtpTestConfig.USER_PASS);
               assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(cmdPass));
            }

            {
               CmdSyst cmdSyst = new CmdSyst();
               assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(cmdSyst));
            }

            assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdDele(FtpTestConfig.TEST_FOLDER)));
         }
      }

      {
         int successed = 0;
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

   private static boolean isServerPresent()
   {
      try
      {
         FtpClientSession client = FtpTestConfig.getTestFtpClient();
         boolean connected = client.connect();

         if (connected)
         {
            client.close();
            return true;
         }

      }
      catch (Exception exc)
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

      public void removeAllFolders(String rootTestFolder)
      {
         log.info("Clearing...");
         try
         {
            FtpClientSession client = new FtpClientSessionImpl("127.0.0.1", 21);
            client.connect();

            assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser("admin")));
            assertEquals(FtpConst.Replyes.REPLY_230, client.executeCommand(new CmdPass("admin")));

            assertEquals(FtpConst.Replyes.REPLY_215, client.executeCommand(new CmdSyst()));
            assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new CmdType("A")));

            for (int i1 = 1; i1 <= ITEMS_COUNT; i1++)
            {
               String folder1 = rootTestFolder + "/folder_" + i1;
               for (int i2 = 1; i2 <= ITEMS_COUNT; i2++)
               {
                  String folder2 = folder1.substring(0);
                  folder2 += "/subfolder_" + i2;
                  for (int i3 = 0; i3 < ITEMS_COUNT; i3++)
                  {
                     String file3 = folder2.substring(0);
                     file3 += "/test_file_" + i3 + ".txt";

                     log.info("Try delete [" + file3 + "]...");
                     assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdRmd(file3)));
                  }

                  log.info("Try delete [" + folder2 + "]...");
                  assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdRmd(folder2)));
               }

               log.info("Try delete [" + folder1 + "]...");
               assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdRmd(folder1)));

            }

            assertEquals(FtpConst.Replyes.REPLY_250, client.executeCommand(new CmdRmd(rootTestFolder)));

            client.close();
         }
         catch (Exception exc)
         {
            log.info("Unhandled exception. " + exc.getMessage(), exc);
         }
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

   public void testNOOP() throws Exception
   {
      Log log = getLogger(FtpConst.Commands.CMD_NOOP);
      log.info("Test...");

      FtpClientSession client = FtpTestConfig.getTestFtpClient();
      client.connect();

      assertEquals(FtpConst.Replyes.REPLY_200, client.executeCommand(new CmdNoop()));

      client.close();

      log.info("Complete.");
   }
View Full Code Here

Examples of org.exoplatform.frameworks.ftpclient.client.FtpClientSession

   public void testUSER() throws Exception
   {
      Log log = getLogger(FtpConst.Commands.CMD_USER);
      log.info("Test...");

      FtpClientSession client = FtpTestConfig.getTestFtpClient();
      client.connect();

      assertEquals(FtpConst.Replyes.REPLY_331, client.executeCommand(new CmdUser("admin")));

      client.close();

      log.info("Complete.");
   }
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.