Hi,
Before connecting using command prompt, i deleted known_hosts file of client machine.
I was still able to connect using command prompt because it automatically created an entry into known_hosts.
After connecting to this machine using command prompt, there is an entry present into known_hosts file.
I don't change this entry at all and try to connect using sshftpclient but it fails for 49222
but not for 22 ( Both tests done using different different code bundles so there should be no confusion ) .
I just don't understand that why only changing remote part in my code is throwing this exception though connection is successfully established using the same port on command promptIn my code, if i don't get an entry into known_hosts file i am using
lftp command to insert an entry into this file.
Here is little code
SSHFTPClient ftp = new SSHFTPClient();
ftp.setRemoteHost(ftpServerIp);
ftp.setRemotePort(49222);
String filePath=homeDir+".ssh"+File.separator+"known_hosts";
ftp.getValidator().loadKnownHosts(filePath);
ftp.setAuthentication(ftpServerUser, ftpServerPassword);
try
{
System.out.println("trying to connect using port-"+ftp.getRemotePort() +", and hostname-"+ftp.getRemoteHost());
ftp.connect();
}catch (Exception e)
{
System.out.println("Going to create a new entry into knownhost file");
String command = "lftp -e 'set net:max-retries 1; set net:timeout 5; cd ;quit' -p 49222 -u "+ftpServerUser+","+ftpServerPassword+" sftp://"+ftpServerIp;
runLinuxCommand(command);
Thread.sleep(5000);
ftp.getValidator().loadKnownHosts(filePath);
ftp.connect();
}