connect to VM with SSH in java

I am new to java and I want to write a code that connects a Linux machine with SSH (with IP and password) make a directiry, and copy my file to there. how can I do this?

this is how it is done in python:

        ssh.connect(automationGW, port=22,
                    username='root', password=passwordGW)
        stdin, stdout, stderr = ssh.exec_command(mkdir /opt/Home/test_files)
        cmdResult = stdout.read()
        scp = SCPClient(ssh.get_transport())
        scp.put(directory + '/finalDir/' + pcapFile, '/opt/Home/test_files')
        ssh.close()

what is the equivalent command in java for: ssh.exec_command and SCPClient(ssh.get_transport()) and scp.put ?

thank you very much.

Answer

You can use jsch.

It has well documented examples as well.

You can use these examples to write a program for creating directory and uploading file easily.