Solved

JSCH libraries asking for Kerberos username and password

Posted on 2014-11-10
3
562 Views
Last Modified: 2014-12-14
I am trying to download a file from a remote file server to my local. I pasted the code at the end of this question. I am getting command prompts as below -

Kerberos username [kalla]: USER1
Kerberos password for test: PWD

Open in new window


Even if I enter values for above queries, I am getting FileNotFound error. How can I fix it?

CODE:

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.Selectors;
import org.apache.commons.vfs2.impl.StandardFileSystemManager;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;

public class GetMyFiles {
	static Properties props;

	public static void main(String[] args) {
		GetMyFiles getMyFiles = new GetMyFiles();
		String propertiesFilename = "C:\\Users\\USER1\\workspace\\Test\\src\\Config.properties";
		String fileToDownload = "FileToBeDownloaded.txt";
		getMyFiles.startFTP(propertiesFilename, fileToDownload);
	}

	public boolean startFTP(String propertiesFilename, String fileToDownload) {
		props = new Properties();
		StandardFileSystemManager manager = new StandardFileSystemManager();
		try {
			props.load(new FileInputStream(propertiesFilename));
			String serverAddress = props.getProperty("serverAddress").trim();
			String userId = props.getProperty("userId").trim();
			String password = props.getProperty("password").trim();
			String remoteDirectory = props.getProperty("remoteDirectory").trim();
			String localDirectory = props.getProperty("localDirectory").trim();
			// Initializes the file manager
			manager.init();
			// Setup our SFTP configuration
			FileSystemOptions opts = new FileSystemOptions();
			SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
			SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
			SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
			// Create the SFTP URI using the host name, userid, password, remote
			// path and file name
			String sftpUri = "sftp://" + userId + ":" + password + "@"
					+ serverAddress + "/" + remoteDirectory + fileToDownload;
			// Create local file object
			String filepath = localDirectory + fileToDownload;
			File file = new File(filepath);
			FileObject localFile = manager.resolveFile(file.getAbsolutePath());
			// Create remote file object
			FileObject remoteFile = manager.resolveFile(sftpUri, opts);
			// Copy local file to sftp server
			localFile.copyFrom(remoteFile, Selectors.SELECT_SELF);
			System.out.println("File download successful");
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		} finally {
			manager.close();
		}
		return true;
	}
}

Open in new window

0
Comment
Question by:Ravi Kalla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Expert Comment

by:Amitkumar Panchal
ID: 40446016
Looking at the imports in the program, it seems program does not use JSCH library.

In case of JSCH, the imports should be like given below:

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

If you are looking for an example to download a file using SFTP protocol, refer below links.
1. http://www.jcraft.com/jsch/examples/Sftp.java.html (This is homepage for JSCH api developers and good example is already given)
2. http://kodehelp.com/java-program-for-downloading-file-from-sftp-server/ (Admin will not allow this, if it is violating a policy.)
0
 
LVL 6

Accepted Solution

by:
Ravi Kalla earned 0 total points
ID: 40489945
I am using WinSCP scripts and triggering them using Java.
0
 
LVL 6

Author Closing Comment

by:Ravi Kalla
ID: 40498713
This is the solution that worked for me.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question