请教两台机器之间文件拷贝的问题 用java实现两台机器之间的文件拷贝,发现开始时必须得用IE访问一次服务器,输入用户名用密码后才能执行拷贝成功,否则连接不上。请问有没有可以在程序里就将用户名和密码指定的方法呢?具体怎么实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ftp://用户名:密码@服务器的地址这样的形式用IE登陆行不?? 除了用FTP方式的还有别的办法吗? 偶有不知道你想不想要?是FTP的可否? 好的,请给我参考一下,发到[email protected]或者直接贴出来吧,谢谢! package bggxy.CL.com;import sun.net.ftp.*;import java.io.*;import java.io.IOException;//import java.util.StringTokenizer;//import java.util.ArrayList;import sun.net.TelnetOutputStream;public class Ftpupload { FtpClient client; private String host="192.168.30.242";//FTP服务器IP private String username="yg";//FTP用户名字 private String password="yg";//FTP密码 private String path = "/"; //目录 private int port = 21; public void connect() { try { client = new FtpClient(host); client.login(username, password); //设置成2进制传输 client.binary(); client.cd(path); System.out.println("登陆成功"); } catch (FtpLoginException e) { System.out.println("无权限相连接" + e.getMessage()); } catch(IOException e){ System.out.println("连接失败"+e.getMessage()); } catch(SecurityException e){ System.out.println("用户名字或者密码不对"); } } public boolean upLoad(String fileName,String filePath) { File localFile = new File(filePath); try { TelnetOutputStream os = client.put(fileName); java.io.File file_in = new java.io.File(filePath); FileInputStream is = new FileInputStream(file_in); byte[] bytes = new byte[1024]; int c; while ( (c = is.read(bytes)) != -1) { os.write(bytes, 0, c); } is.close(); os.close(); System.out.println("传送成功"); } catch (Exception e) { System.out.println("上传文件出错"+e.getMessage()); return false; } return true; } public void closeServer()throws Exception{ if(client!=null){ client.closeServer(); System.out.println("FTP已经关闭"); } }}你自己应该会调用这个类吧???呵呵好用了可别忘了给偶分呀。 给分的话给这个号的分那个是我的临时号。提醒你一点:在jsp中调用的时候这样调用:<%Ftpupload.connect();boolean upfile = Ftpupload.upLoad("aaa.txt","c:/aaa.txt");%>好的。别加错分喽。 另一外一点,得在FTP服务器上建一个FTP服务器。这样就一切都平静了!!! socket 的异步通信 求eclipse的下载地址? 说不同国语的人可以相互沟通吗?? 变量和变量的值..与健值对的健,与值,有什么区别 Ask a problem about "list" 项目管理人员和想做项目管理的人,快出招!!!! 如何让EDT线程工作完后再运行主线程 如何使用正则表达。 当一个工作流项目经理(用Java和Lotus开发),需要那些知识?紧急!!! 单向链表能否用快速排序??如果能如何实现?? String a=new String("foo");一共产生了几个对象?为什么??谢谢! JAVA初学者有几个问题请教?
这样的形式用IE登陆行不??
是FTP的可否?
import java.io.*;
import java.io.IOException;
//import java.util.StringTokenizer;
//import java.util.ArrayList;
import sun.net.TelnetOutputStream;public class Ftpupload {
FtpClient client;
private String host="192.168.30.242";//FTP服务器IP
private String username="yg";//FTP用户名字
private String password="yg";//FTP密码
private String path = "/"; //目录
private int port = 21; public void connect() {
try {
client = new FtpClient(host);
client.login(username, password);
//设置成2进制传输
client.binary();
client.cd(path);
System.out.println("登陆成功");
}
catch (FtpLoginException e) {
System.out.println("无权限相连接" + e.getMessage());
}
catch(IOException e){
System.out.println("连接失败"+e.getMessage());
}
catch(SecurityException e){
System.out.println("用户名字或者密码不对");
} }
public boolean upLoad(String fileName,String filePath) {
File localFile = new File(filePath); try {
TelnetOutputStream os = client.put(fileName);
java.io.File file_in = new java.io.File(filePath);
FileInputStream is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ( (c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
is.close();
os.close();
System.out.println("传送成功"); }
catch (Exception e) {
System.out.println("上传文件出错"+e.getMessage());
return false;
}
return true;
}
public void closeServer()throws Exception{
if(client!=null){
client.closeServer();
System.out.println("FTP已经关闭");
}
}
}你自己应该会调用这个类吧???呵呵好用了可别忘了给偶分呀。
提醒你一点:在jsp中调用的时候这样调用:
<%
Ftpupload.connect();
boolean upfile = Ftpupload.upLoad("aaa.txt","c:/aaa.txt");
%>
好的。别加错分喽。