Package org.apache.sshd.client

Examples of org.apache.sshd.client.SftpClient


        Utils.deleteRecursive(new File("target/sftp"));
        new File("target/sftp").mkdirs();
        new File("target/sftp/client/test.txt").delete();
        new File("target/sftp/client").delete();

        SftpClient sftp = session.createSftpClient();

        sftp.mkdir("target/sftp/client");

        SftpClient.Handle h = sftp.open("target/sftp/client/test.txt", EnumSet.of(SftpClient.OpenMode.Write));
        byte[] d = "0123456789\n".getBytes();
        sftp.write(h, 0, d, 0, d.length);
        sftp.write(h, d.length, d, 0, d.length);

        SftpClient.Attributes attrs = sftp.stat(h);
        Assert.assertNotNull(attrs);

        sftp.close(h);

        h = sftp.openDir("target/sftp/client");
        SftpClient.DirEntry[] dir = sftp.readDir(h);
        assertNotNull(dir);
        assertEquals(1, dir.length);
        assertNull(sftp.readDir(h));
        sftp.close(h);

        sftp.remove("target/sftp/client/test.txt");

        OutputStream os = sftp.write("target/sftp/client/test.txt");
        os.write(new byte[1024 * 128]);
        os.close();

        InputStream is = sftp.read("target/sftp/client/test.txt");
        is.read(new byte[1024 * 128]);
        int i = is.read();
        is.close();

        int nb = 0;
        for (SftpClient.DirEntry entry : sftp.readDir("target/sftp/client")) {
            nb++;
        }
        assertEquals(1, nb);

        sftp.remove("target/sftp/client/test.txt");

        sftp.rmdir("target/sftp/client/");

        sftp.close();

        client.stop();
    }
View Full Code Here


        Utils.deleteRecursive(new File("target/sftp"));
        new File("target/sftp").mkdirs();
        new File("target/sftp/client/test.txt").delete();
        new File("target/sftp/client").delete();

        SftpClient sftp = session.createSftpClient();

        sftp.mkdir("target/sftp/client");

        SftpClient.Handle h = sftp.open("target/sftp/client/test.txt", EnumSet.of(SftpClient.OpenMode.Write));
        byte[] d = "0123456789\n".getBytes();
        sftp.write(h, 0, d, 0, d.length);
        sftp.write(h, d.length, d, 0, d.length);

        SftpClient.Attributes attrs = sftp.stat(h);
        Assert.assertNotNull(attrs);

        sftp.close(h);

        h = sftp.openDir("target/sftp/client");
        SftpClient.DirEntry[] dir = sftp.readDir(h);
        assertNotNull(dir);
        assertEquals(1, dir.length);
        assertNull(sftp.readDir(h));
        sftp.close(h);

        sftp.remove("target/sftp/client/test.txt");

        OutputStream os = sftp.write("target/sftp/client/test.txt");
        os.write(new byte[1024 * 128]);
        os.close();

        InputStream is = sftp.read("target/sftp/client/test.txt");
        is.read(new byte[1024 * 128]);
        int i = is.read();
        is.close();

        int nb = 0;
        for (SftpClient.DirEntry entry : sftp.readDir("target/sftp/client")) {
            nb++;
        }
        assertEquals(1, nb);

        sftp.remove("target/sftp/client/test.txt");

        sftp.rmdir("target/sftp/client/");

        sftp.close();

        client.stop();
    }
View Full Code Here

        Utils.deleteRecursive(new File("target/sftp"));
        new File("target/sftp").mkdirs();
        new File("target/sftp/client/test.txt").delete();
        new File("target/sftp/client").delete();

        SftpClient sftp = session.createSftpClient();

        sftp.mkdir("target/sftp/client");

        SftpClient.Handle h = sftp.open("target/sftp/client/test.txt", EnumSet.of(SftpClient.OpenMode.Write));
        byte[] d = "0123456789\n".getBytes();
        sftp.write(h, 0, d, 0, d.length);
        sftp.write(h, d.length, d, 0, d.length);

        SftpClient.Attributes attrs = sftp.stat(h);
        Assert.assertNotNull(attrs);

        sftp.close(h);

        h = sftp.openDir("target/sftp/client");
        SftpClient.DirEntry[] dir = sftp.readDir(h);
        assertNotNull(dir);
        assertEquals(1, dir.length);
        assertNull(sftp.readDir(h));
        sftp.close(h);

        sftp.remove("target/sftp/client/test.txt");

        OutputStream os = sftp.write("target/sftp/client/test.txt");
        os.write(new byte[1024 * 128]);
        os.close();

        InputStream is = sftp.read("target/sftp/client/test.txt");
        is.read(new byte[1024 * 128]);
        int i = is.read();
        is.close();

        int nb = 0;
        for (SftpClient.DirEntry entry : sftp.readDir("target/sftp/client")) {
            nb++;
        }
        assertEquals(1, nb);

        sftp.remove("target/sftp/client/test.txt");

        sftp.rmdir("target/sftp/client/");

        sftp.close();

        client.stop();
    }
View Full Code Here

TOP

Related Classes of org.apache.sshd.client.SftpClient

Copyright © 2018 www.massapicom. 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.