• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

com.jcraft.jsch.JSchException: connection is closed by foreign host

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Jsch APIs to make a simple program to list the files on the FileZill FTP server for a user “admin”

While running the same I am getting
com.jcraft.jsch.JSchException: connection is closed by foreign host
at com.jcraft.jsch.Session.connect(Session.java:271)
at com.jcraft.jsch.Session.connect(Session.java:153)
at test.CLISftp.main(CLISftp.java:18)

please help me to solve the problem .

the program is ======

package test;

import com.jcraft.jsch.*;
import java.util.*;

public class CLISftp{
public static void main(String[] arg){

Session session = null;
try{
JSch jsch=new JSch();

String host="localhost";
String user="admin";
session=jsch.getSession(user, host, 21);
session.setUserInfo(new MyUserInfo());
session.setPassword("");
session.connect();

Channel channel=session.openChannel("sftp");
channel.connect();
ChannelSftp c=(ChannelSftp)channel;

//get a directory listing
Vector v = c.ls("*");
for(int i = 0; i < v.size();i++){
System.out.println(v.get(i));
}
}
catch(Exception ex){
ex.printStackTrace();
}
finally{
//always disconnect in a finally block or the conenction will be hang
session.disconnect();
}
}

private static class MyUserInfo implements UserInfo {

public String getPassphrase() {
return null;
}

public String getPassword() {
return null;
}

public boolean promptPassphrase(String arg0) {
// TODO Auto-generated method stub
return false;
}

public boolean promptPassword(String arg0) {
// TODO Auto-generated method stub
return false;
}

//There is no keystore on the clientside so just
//accept the serverkey.
public boolean promptYesNo(String arg0) {
// TODO Auto-generated method stub
return true;
}

public void showMessage(String arg0) {
//System.out.println(arg0);
}

};
}
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is Yes it is!
(maybe you meant to ask this question in another forum? and maybe look at your display name at the same time?)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic