Search in sources :

Example 1 with FTPUtils

use of com.cas.sim.tis.util.FTPUtils in project TeachingInSimulation by ScOrPiOzzy.

the class LnkParser2 method getUtil.

private FTPUtils getUtil(String user, String password) {
    FTPUtils util = new FTPUtils();
    FTPClient client = new FTPClient();
    util.setFtpClient(client);
    util.setHost("192.168.1.122");
    util.setPort(21);
    util.setUsername(user);
    util.setPassword(password);
    return util;
}
Also used : FTPUtils(com.cas.sim.tis.util.FTPUtils) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 2 with FTPUtils

use of com.cas.sim.tis.util.FTPUtils in project TeachingInSimulation by ScOrPiOzzy.

the class FileDownload method getUtil.

private FTPUtils getUtil(String user, String password) {
    FTPUtils util = new FTPUtils();
    FTPClient client = new FTPClient();
    util.setFtpClient(client);
    util.setHost("192.168.1.123");
    util.setPort(21);
    util.setUsername(user);
    util.setPassword(password);
    return util;
}
Also used : FTPUtils(com.cas.sim.tis.util.FTPUtils) FTPClient(org.apache.commons.net.ftp.FTPClient)

Example 3 with FTPUtils

use of com.cas.sim.tis.util.FTPUtils in project TeachingInSimulation by ScOrPiOzzy.

the class FileDownload method testDownload.

@Test
public void testDownload() throws Exception {
    FTPUtils ftpUtils = getUtil("admin", "admin");
    List<String> pathArray = new ArrayList<>();
    boolean f = ftpUtils.connect("/assets");
    System.out.println(f);
    ftpUtils.getPath("/assets", pathArray);
    pathArray.forEach(System.out::println);
    ftpUtils.download(pathArray, "./");
    ftpUtils.disconnect();
}
Also used : ArrayList(java.util.ArrayList) FTPUtils(com.cas.sim.tis.util.FTPUtils) Test(org.junit.Test)

Example 4 with FTPUtils

use of com.cas.sim.tis.util.FTPUtils in project TeachingInSimulation by ScOrPiOzzy.

the class FileDownload method testUpload.

@Test
public void testUpload() throws Exception {
    // 管理员可以上传文件
    FTPUtils util = getUtil("admin", "admin");
    boolean result = util.uploadFile("/assets/Model", new File("G:\\jfxrt.jar"), System.currentTimeMillis() + ".jar");
    Assert.assertTrue(result);
    // 匿名用户不允许上传
    util = getUtil("anonymous", "");
    result = util.uploadFile("/assets/Model", new File("G:\\jfxrt.jar"), System.currentTimeMillis() + ".jar");
    Assert.assertFalse(result);
}
Also used : FTPUtils(com.cas.sim.tis.util.FTPUtils) File(java.io.File) Test(org.junit.Test)

Example 5 with FTPUtils

use of com.cas.sim.tis.util.FTPUtils in project TeachingInSimulation by ScOrPiOzzy.

the class FileDownload method testConcurrent.

@Test
public void testConcurrent() throws Exception {
    FTPUtils util = getUtil("anonymous", "");
    StopWatch w = new StopWatch();
    w.start("开始下载");
    InputStream stream = util.downloadFile("/assets/Model/", "11.j3o");
    FileOutputStream out;
    try {
        File file;
        out = new FileOutputStream(file = new File("model-file-" + 0));
        Util.copyStream(stream, out);
        out.close();
        // 服务器中11.j3o文件大小是3,506,624
        Assert.assertEquals(3506624, file.length());
        w.stop();
        System.out.println(w.getTotalTimeMillis());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) FTPUtils(com.cas.sim.tis.util.FTPUtils) IOException(java.io.IOException) File(java.io.File) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Aggregations

FTPUtils (com.cas.sim.tis.util.FTPUtils)8 Test (org.junit.Test)5 File (java.io.File)3 FTPClient (org.apache.commons.net.ftp.FTPClient)3 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Bean (org.springframework.context.annotation.Bean)1 StopWatch (org.springframework.util.StopWatch)1