类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
显示“无权限与主机相连”,不知道哪里出问题了,还请各位赐教。
下面是主要代码:(初始化已经略去了)
//判断是否连接
public boolean connect(String hostname,String uid,String pwd){
this.hostname = hostname;
jLabel4.setText("正在连接,请等待.....");
try{
aftp =new FtpClient(hostname);
aftp.login(uid,pwd);
aftp.binary();
//showFileContents();
}
catch(FtpLoginException e){
a="无权限与主机:"+hostname+"连接!";
jLabel4.setText(a);
return false;
}
catch (IOException e){
a="连接主机:"+hostname+"失败!";
jLabel4.setText(a);
return false;
}
catch(SecurityException e)
{
a="无权限与主机:"+hostname+"连接!";
jLabel4.setText(a);
return false;
}
jLabel4.setText("连接主机:"+hostname+"成功!");
return true;
}
//断开连接
public void stop()
{
try
{
aftp.closeServer();
}
catch(IOException e)
{
}
}
void jButton1_mouseClicked(MouseEvent e) {
jLabel4.setText("正在连接,请等待.....");
if (connect(jTextField1.getText(), jTextField2.getText(),jTextField3.getText())) {
jButton1.setEnabled(false);
jButton2.setEnabled(true);
}
}
void jButton2_mouseClicked(MouseEvent e) {
stop();
jButton1.enable(true);
jButton2.enable(false);
jLabel4.setText("与主机"+hostname+"连接已断开!");
}
}
网友回答: