Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 300,494 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,862 people online right now. Registration is fast and FREE... Join Now!




accessing unix

 

accessing unix

javamad

1 Jul, 2009 - 07:17 AM
Post #1

D.I.C Head
**

Joined: 8 Jun, 2009
Posts: 65



Thanked: 1 times
My Contributions
Hi I have some code which has a couple of errors which i cannot find a solution.

Below is code to access the unix environment in java using shhtools. I however get errors around the shh.connect and FTPException statements. Could someone have a look and let me know what I need to add to fix these problems please

Many thanks


CODE

package DataCapture;

public class Main {

    public static void main(String args[]) {
        
        
        String serverName = "xx";
        String portNumber = "xx";
        String userName = "xx";
        String password = "xx";
        String databaseName = "xx";
    
        UnixConn Uconn = new UnixConn(serverName, portNumber, userName, password);
    
        
    }
        
}





CODE


public class UnixConn {

    public UnixConn(String serverName, String portNumber, String userName, String password){
        
        String host = serverName;
        String port = portNumber;
        
        String filePath ="";
        
        
        SshClient ssh = new SshClient();
        ssh.connect(host, port); //The method connect(String, HostKeyVerification) in the type SshClient is not applicable for the arguments (String, String)
        //Authenticate
        PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
        passwordAuthenticationClient.setUsername(userName);
        passwordAuthenticationClient.setPassword(password);
        int result = ssh.authenticate(passwordAuthenticationClient);
        if(result != AuthenticationProtocolState.COMPLETE){
             throw new FTPException("Login to " + host + ":" + port + " " + userName + "/" + password + " failed"); //FTPException cannot be resolved to a type
        }
        //Open the SFTP channel
        SftpClient client = ssh.openSftpClient();
        //Send the file
        client.put(filePath);
        //disconnect
        client.quit();
        ssh.disconnect();


        
        
    }
    
}


User is offlineProfile CardPM
+Quote Post


mostyfriedman

RE: Accessing Unix

1 Jul, 2009 - 07:40 AM
Post #2

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,148



Thanked: 355 times
Dream Kudos: 600
Expert In: Learning

My Contributions
can you give us some info about the errors you are recieving?
User is offlineProfile CardPM
+Quote Post

javamad

RE: Accessing Unix

1 Jul, 2009 - 07:43 AM
Post #3

D.I.C Head
**

Joined: 8 Jun, 2009
Posts: 65



Thanked: 1 times
My Contributions
Hi, errors are commented in the code and consol output is below.
Thanks

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method connect(String, HostKeyVerification) in the type SshClient is not applicable for the arguments (String, String)
FTPException cannot be resolved to a type

at DataCapture.UnixConn.<init>(UnixConn.java:22)
at DataCapture.Main.main(Main.java:21)

User is offlineProfile CardPM
+Quote Post

mostyfriedman

RE: Accessing Unix

1 Jul, 2009 - 07:56 AM
Post #4

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,148



Thanked: 355 times
Dream Kudos: 600
Expert In: Learning

My Contributions
ok, the connect method doesnt take 2 strings as arguments it takes a String and a HostKeyVerification, its all described in the error message you got..so you'll have to pass a HostKeyVerification as the second argument
User is offlineProfile CardPM
+Quote Post

javamad

RE: Accessing Unix

1 Jul, 2009 - 08:02 AM
Post #5

D.I.C Head
**

Joined: 8 Jun, 2009
Posts: 65



Thanked: 1 times
My Contributions
Thanks, Could you let me know how I do that please (I'm still very new to java)
Many thanks for your help

This post has been edited by javamad: 1 Jul, 2009 - 08:05 AM
User is offlineProfile CardPM
+Quote Post

mostyfriedman

RE: Accessing Unix

1 Jul, 2009 - 08:07 AM
Post #6

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,148



Thanked: 355 times
Dream Kudos: 600
Expert In: Learning

My Contributions
ok i'll try..well are you using non standard java classes here??..coz i cant find a class called sshclient in the API..or did you write this class yourself?
User is offlineProfile CardPM
+Quote Post

javamad

RE: Accessing Unix

1 Jul, 2009 - 08:13 AM
Post #7

D.I.C Head
**

Joined: 8 Jun, 2009
Posts: 65



Thanked: 1 times
My Contributions
yes they are non standard (I didn't write them myself though, not that clever)!! downloaded from sourceforge
http://sourceforge.net/projects/sshtools
User is offlineProfile CardPM
+Quote Post

mostyfriedman

RE: Accessing Unix

1 Jul, 2009 - 08:15 AM
Post #8

Striving Student
Group Icon

Joined: 24 Oct, 2008
Posts: 3,148



Thanked: 355 times
Dream Kudos: 600
Expert In: Learning

My Contributions
ah i see, ok here's what you can do..open the HostKeyVerification class and look at the constructor of the class, what arguments does it take and all..then create a HostKeyVerification object then pass it to the connect method
User is offlineProfile CardPM
+Quote Post

javamad

RE: Accessing Unix

1 Jul, 2009 - 08:34 AM
Post #9

D.I.C Head
**

Joined: 8 Jun, 2009
Posts: 65



Thanked: 1 times
My Contributions
Thanks, looked at HostKeyVerification class and found only this:

// (version 1.4 : 48.0, no super bit)
public abstract interface com.sshtools.j2ssh.transport.HostKeyVerification {

// Method descriptor #4 (Ljava/lang/String;Lcom/sshtools/j2ssh/transport/publickey/SshPublicKey;)Z
public abstract boolean verifyHost(java.lang.String arg0, com.sshtools.j2ssh.transport.publickey.SshPublicKey arg1) throws com.sshtools.j2ssh.transport.TransportProtocolException;
}

any suggestions how I can find the class constructor (or other solution to my woes).
Thanks
User is offlineProfile CardPM
+Quote Post

javamad

RE: Accessing Unix

1 Jul, 2009 - 08:57 AM
Post #10

D.I.C Head
**

Joined: 8 Jun, 2009
Posts: 65



Thanked: 1 times
My Contributions
I've managed to do as suggested and fixed the ssh.connect issue, Its only the FTPException erro that I'm stuck with now

Could someone have a look please
Thanks for your help so far
User is offlineProfile CardPM
+Quote Post

malerv

RE: Accessing Unix

1 Jul, 2009 - 09:18 AM
Post #11

D.I.C Head
**

Joined: 1 Jul, 2009
Posts: 85



Thanked: 7 times
My Contributions
I have no skills to answer you're question but I looked at the project's sourceforge space.
Did you look at the documentation of this project?
They provide a getting started that seem (I don't look deeply) usefull.
User is offlineProfile CardPM
+Quote Post

fsloke

RE: Accessing Unix

18 Jul, 2009 - 04:38 AM
Post #12

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 312



Thanked: 9 times
My Contributions
It this post still active?

javamad how your progress?

Any update?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:43AM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month