急求java做的ftp软件源码(GUI)界面 如果人民币处理可以考虑,是我做的,可以提供技术支持。效果基本跟leafftp差不多 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CuteFTP里的那个文件列表显示在JAVA里是用什么控件实现的啊? 这是一个FTP的基本模型,你可以Copy过去运行的,你可以参考着改改,它是APPLetimport sun.net.ftp.*;import sun.net.*;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.io.*;public class FtpApplet extends Applet{ FtpClient aftp; DataOutputStream outputs ; TelnetInputStream ins; TelnetOutputStream outs; TextArea lsArea; Label LblPrompt; Button BtnConn; Button BtnClose; TextField TxtUID; TextField TxtPWD; TextField TxtHost; int ch; public String a="没有连接主机"; String hostname=""; public void init () { setBackground(Color.white); setLayout(new GridBagLayout()); GridBagConstraints GBC = new GridBagConstraints(); LblPrompt = new Label("没有连接主机"); LblPrompt.setAlignment(Label.LEFT); BtnConn = new Button("连接"); BtnClose = new Button("断开"); BtnClose.setEnabled(false); TxtUID = new TextField("",15); TxtPWD = new TextField("",15); TxtPWD.setEchoChar('*'); TxtHost = new TextField("",20); Label LblUID = new Label("User ID:"); Label LblPWD = new Label("PWD:"); Label LblHost = new Label("Host:"); lsArea = new TextArea(30,80); lsArea.setEditable(false); GBC.gridwidth= GridBagConstraints.REMAINDER; GBC.fill = GridBagConstraints.HORIZONTAL; ((GridBagLayout)getLayout()).setConstraints(LblPrompt,GBC); add(LblPrompt); GBC.gridwidth=1; ((GridBagLayout)getLayout()).setConstraints(LblHost,GBC); add(LblHost); GBC.gridwidth=GridBagConstraints.REMAINDER; ((GridBagLayout)getLayout()).setConstraints(TxtHost,GBC); add(TxtHost); GBC.gridwidth=1; ((GridBagLayout)getLayout()).setConstraints(LblUID,GBC); add(LblUID); GBC.gridwidth=1; ((GridBagLayout)getLayout()).setConstraints(TxtUID,GBC); add(TxtUID); GBC.gridwidth=1; ((GridBagLayout)getLayout()).setConstraints(LblPWD,GBC); add(LblPWD); GBC.gridwidth=1; ((GridBagLayout)getLayout()).setConstraints(TxtPWD,GBC); add(TxtPWD); GBC.gridwidth=1; GBC.weightx=2; ((GridBagLayout)getLayout()).setConstraints(BtnConn,GBC); add(BtnConn); GBC.gridwidth=GridBagConstraints.REMAINDER; ((GridBagLayout)getLayout()).setConstraints(BtnClose,GBC); add(BtnClose); GBC.gridwidth=GridBagConstraints.REMAINDER; GBC.fill = GridBagConstraints.HORIZONTAL; ((GridBagLayout)getLayout()).setConstraints(lsArea,GBC); add(lsArea); } public boolean connect(String hostname, String uid,String pwd) { this.hostname = hostname; LblPrompt.setText("正在连接,请等待....."); try { aftp =new FtpClient(hostname); aftp.login(uid,pwd); aftp.binary(); showFileContents(); } catch(FtpLoginException e) { a="无权限与主机:"+hostname+"连接!"; LblPrompt.setText(a); return false; } catch (IOException e) { a="连接主机:"+hostname+"失败!"; LblPrompt.setText(a); return false; } catch(SecurityException e) { a="无权限与主机:"+hostname+"连接!"; LblPrompt.setText(a); return false; } LblPrompt.setText("连接主机:"+hostname+"成功!"); return true; } public void stop() { try { aftp.closeServer(); } catch(IOException e) { } } public void paint(Graphics g) { } public boolean action(Event evt,Object obj) { if (evt.target == BtnConn) { LblPrompt.setText("正在连接,请等待....."); if (connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText())) { BtnConn.setEnabled(false); BtnClose.setEnabled(true); } return true; } if (evt.target == BtnClose) { stop(); BtnConn.setEnabled(true); BtnClose.setEnabled(false); LblPrompt.setText("与主机"+hostname+"连接已断开!"); return true; } return super.action(evt,obj); } public boolean sendFile(String filepathname) { boolean result=true; if (aftp != null) { LblPrompt.setText("正在粘贴文件,请耐心等待...."); String contentperline; try { a="粘贴成功!"; String fg =new String("\\"); int index = filepathname.lastIndexOf(fg); String filename = filepathname.substring(index+1); File localFile ; localFile = new File(filepathname) ; RandomAccessFile sendFile = new RandomAccessFile(filepathname,"r");// sendFile.seek(0); outs = aftp.put(filename); outputs = new DataOutputStream(outs); while (sendFile.getFilePointer() < sendFile.length() ) { ch = sendFile.read(); outputs.write(ch); } outs.close(); sendFile.close(); } catch(IOException e) { a = "粘贴失败!"; result = false ; } LblPrompt.setText(a); showFileContents(); } else { result = false; } return result; } public void showFileContents() { StringBuffer buf = new StringBuffer(); lsArea.setText(""); try { ins= aftp.list(); while ((ch=ins.read())>=0) { buf.append((char)ch); } lsArea.append(buf.toString()); ins.close(); } catch(IOException e) { } } public static void main(String args[]) { Frame f = new Frame("FTP Client"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); FtpApplet ftp = new FtpApplet(); ftp.init(); ftp.start(); f.add(ftp); f.pack(); f.setVisible(true); }} 这个程序对楼主可能有用,但我想要的是可以想JFileChooser那样显示文件,然后可以选择某个文件或进入某个目录。 switch语句的怪异??? -------------------大家在开发系统的时候,都是开发到什么阶段开始在数据库建立VIEW--------------------- 不好意思请问如何验证四则运算数学表达式的合法性? 需要<标识符>? 有哪位兄弟懂得如何处理UDP协议传输乱码问题的 求助(连接数据库)为什么会报错? 请教大侠们一个小题目--新手提问. 帮菜鸟一把,谢谢! 我的JDK里怎么没有jar? 大家来谈谈java语言的书写规则吧。(分数不断增加中) JDK可以为什么JB就不行呢?这对我很重要先谢了! 菜鸟求教!!感激死我!!
import sun.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;public class FtpApplet extends Applet
{
FtpClient aftp;
DataOutputStream outputs ;
TelnetInputStream ins;
TelnetOutputStream outs;
TextArea lsArea;
Label LblPrompt;
Button BtnConn;
Button BtnClose;
TextField TxtUID;
TextField TxtPWD;
TextField TxtHost;
int ch;
public String a="没有连接主机";
String hostname=""; public void init ()
{
setBackground(Color.white);
setLayout(new GridBagLayout());
GridBagConstraints GBC = new GridBagConstraints();
LblPrompt = new Label("没有连接主机");
LblPrompt.setAlignment(Label.LEFT); BtnConn = new Button("连接");
BtnClose = new Button("断开");
BtnClose.setEnabled(false);
TxtUID = new TextField("",15);
TxtPWD = new TextField("",15);
TxtPWD.setEchoChar('*');
TxtHost = new TextField("",20);
Label LblUID = new Label("User ID:");
Label LblPWD = new Label("PWD:");
Label LblHost = new Label("Host:"); lsArea = new TextArea(30,80);
lsArea.setEditable(false); GBC.gridwidth= GridBagConstraints.REMAINDER;
GBC.fill = GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(LblPrompt,GBC);
add(LblPrompt); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblHost,GBC);
add(LblHost);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(TxtHost,GBC);
add(TxtHost); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblUID,GBC);
add(LblUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtUID,GBC);
add(TxtUID); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblPWD,GBC);
add(LblPWD);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtPWD,GBC);
add(TxtPWD); GBC.gridwidth=1;
GBC.weightx=2;
((GridBagLayout)getLayout()).setConstraints(BtnConn,GBC);
add(BtnConn);
GBC.gridwidth=GridBagConstraints.REMAINDER; ((GridBagLayout)getLayout()).setConstraints(BtnClose,GBC);
add(BtnClose); GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill = GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(lsArea,GBC);
add(lsArea);
} public boolean connect(String hostname, String uid,String pwd)
{
this.hostname = hostname;
LblPrompt.setText("正在连接,请等待.....");
try
{
aftp =new FtpClient(hostname);
aftp.login(uid,pwd);
aftp.binary();
showFileContents();
}
catch(FtpLoginException e)
{
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
catch (IOException e)
{
a="连接主机:"+hostname+"失败!";
LblPrompt.setText(a);
return false;
}
catch(SecurityException e)
{
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
LblPrompt.setText("连接主机:"+hostname+"成功!");
return true;
} public void stop()
{
try
{
aftp.closeServer();
}
catch(IOException e)
{
}
} public void paint(Graphics g)
{
} public boolean action(Event evt,Object obj)
{
if (evt.target == BtnConn)
{
LblPrompt.setText("正在连接,请等待.....");
if (connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText()))
{
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
}
return true;
}
if (evt.target == BtnClose)
{
stop();
BtnConn.setEnabled(true);
BtnClose.setEnabled(false);
LblPrompt.setText("与主机"+hostname+"连接已断开!");
return true;
}
return super.action(evt,obj);
} public boolean sendFile(String filepathname)
{
boolean result=true;
if (aftp != null)
{
LblPrompt.setText("正在粘贴文件,请耐心等待...."); String contentperline;
try
{
a="粘贴成功!";
String fg =new String("\\");
int index = filepathname.lastIndexOf(fg);
String filename = filepathname.substring(index+1);
File localFile ;
localFile = new File(filepathname) ;
RandomAccessFile sendFile = new RandomAccessFile(filepathname,"r");
//
sendFile.seek(0);
outs = aftp.put(filename);
outputs = new DataOutputStream(outs);
while (sendFile.getFilePointer() < sendFile.length() )
{
ch = sendFile.read();
outputs.write(ch);
}
outs.close();
sendFile.close();
}
catch(IOException e)
{
a = "粘贴失败!";
result = false ; }
LblPrompt.setText(a);
showFileContents();
}
else
{
result = false;
}
return result;
} public void showFileContents()
{
StringBuffer buf = new StringBuffer();
lsArea.setText("");
try
{
ins= aftp.list();
while ((ch=ins.read())>=0)
{
buf.append((char)ch);
}
lsArea.append(buf.toString());
ins.close();
}
catch(IOException e)
{
}
} public static void main(String args[])
{
Frame f = new Frame("FTP Client");
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
FtpApplet ftp = new FtpApplet();
ftp.init();
ftp.start();
f.add(ftp);
f.pack();
f.setVisible(true);
}
}