확인
public static void readRemoteManifestFile(String ipAddress,String filePath,String username,String password){
//filePath="/usr/local/tomcat/webapps/abc/test/NavigationPanel.html";
try {
StandardFileSystemManager manager = new StandardFileSystemManager();
manager.init();
FileObject remoteFile = manager.resolveFile(createConnectionString(ipAddress, username,password,
filePath), createDefaultOptions());
if(!remoteFile.exists()){
System.out.println(filePath+": no such file");
}else{
Reader inputStreamReader = new InputStreamReader( remoteFile.getContent().getInputStream());
char c;
int i;
while((i=inputStreamReader.read())!=-1)
{
// int to character
c=(char)i;
// print char
System.out.println("Character Read: "+c);
}
}
} catch (Exception e) {
System.out.println("Failed to read for "+
filePath+": "+e);
System.out.println("Failed to read for "+
filePath+": "+e.getMessage());
}
}
public static String createConnectionString(String hostName,
String username, String password, String remoteFilePath) {
return "sftp://" + username + ":" + password + "@" + hostName + "/" + remoteFilePath;
}
public static FileSystemOptions createDefaultOptions()
throws FileSystemException {
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
opts, "no");
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
return opts;
}
}
geeting 파일을 찾을 수없는 예외 –
java.net.ConnectException 점점 : FTP 프로토콜을 사용하는 경우 연결이 거부되었습니다. –