The servers trust each other and do not have to use a password. I know that my code has a password in it right now, but the problem I am having is at the
ssh.connect(). I am getting this error:
null
[Ljava.lang.StackTraceElement;@84da23
I think that I have authentic a key from the server that I am trying to connect to but I am unsure how I am supposed to do that and am having trouble finding any code examples on that.
Please help
Thanks
Expand|Select|Wrap|Line Numbers
- private void ftpFile(String actionType,String user,String password,String host,String remoteDirFile,String remoteFILE,String localeFile,String modeType)
- {
- //modeType='a' for ascii || 'i' for binary
- if(actionType.equalsIgnoreCase("download")) ///Download a file
- {
- try
- {
- System.out.println("YOU GOT TO FTPFILE");
- SshClient ssh = new SshClient();
- System.out.println("BEFORE CONNECT: " + host);
- ssh.connect(host, 22);
- System.out.println("BEFORE AUTHENTICATION");
- //Authenticate
- PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
- passwordAuthenticationClient.setUsername(user);
- passwordAuthenticationClient.setPassword(password);
- int result = ssh.authenticate(passwordAuthenticationClient);
- if(result != AuthenticationProtocolState.COMPLETE){
- System.out.println("Login to " + host + ":" + " " + user + "/" + password + " failed");
- }
- //Open the SFTP channel
- System.out.println("OPENING THE SFTP CHANNEL");
- SftpClient client = ssh.openSftpClient();
- System.out.println("TRYING TO SEND THE FILE");
- //Send the file
- client.get(remoteDirFile,localeFile);
- System.out.println("SENDING THE FILE");
- //disconnect
- client.quit();
- ssh.disconnect();
- System.out.println("DISCONNECTION FROM THE SSH");
- //This ftp is used for ftping in CBOE and not over a network. The above is used for secure ftp over a network
- /*
- URL url = new URL("ftp://"+user+":"+password+"@"+host+".cboe.com:21/%2F"+remoteDirFile+";type="+modeType);
- URLConnection conn = url.openConnection();
- PrintWriter ot = new PrintWriter(new FileWriter(localeFile));
- BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line="";
- while((line = in.readLine()) != null)
- {
- ot.println(line);
- }
- ot.close();
- in.close();
- */
- }
- catch (MalformedURLException m)
- {
- System.out.println("YOU FAILED IN THE CONNECT11");
- System.out.println(" Error: "+m);
- }
- catch (IOException ioe)
- {
- System.out.println("YOU FAILED IN THE CONNECT");
- System.out.println(" Error: "+ioe);
- String weekDay = convertToValidWeekDay(determineValidWeekDay((new GregorianCalendar().get(Calendar.DAY_OF_WEEK + day--))));
- if(day < -7)
- {
- System.out.println(" No valid file(s) to "+actionType);
- }
- String remoteDirFile2="/infra/"+weekDay+"/prdgc2a/"+ remoteFILE;
- //ftpFile(actionType,user,password,host,remoteDirFile2,remoteFILE,localeFile,modeType);
- }
- }