FTP上传大文件问题 本人用IIS搭建了一个FTP服务器,用JAVA编写了一个定时FTP的程序,测试时使用的多个小文件(2M)测试成功,正式使用时上传60M的文件就出问题,症状如下:上传多个60多M的文件时通常第一个文件可以上传成功,但紧接着程序停止循环,没有任何错误提示的停止在那里,这是什么原因。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void FTPFILE() { String msg = ""; String hostname = getFtpSerIp(); int port = 21; String uid = getFtpSerUser(); String pwd = getFtpSerPsw(); String RWFileDir = getLocalFileDir();// 文件目录 String LocalPathCh = getLocalFileDirChild(); String ServerPath = getFtpFileDir(); // 连接ftp服务器 FtpApplet ft = new FtpApplet(); ft.connect(RWFileDir, hostname, port, uid, pwd); // 上传文件 if (ft.aftp != null) { File fdir = new File(RWFileDir); String FileName = ""; File fileup = null; int fdirlen = fdir.list().length; for (int i = 0; i < fdirlen; i++) { FileName = RWFileDir + (fdir.list())[i]; fileup = new File(FileName); if(fileup.isFile() && FileName.lastIndexOf(".zip") > -1 ) { //备份压缩文件 msg = ft.copyFile(FileName,getLocalFileDirCopy() + fileup.getName()); ft.log(RWFileDir, msg);//写入日志文件 System.out.println(msg); //上传文件 ft.uploadFile(RWFileDir, FileName,LocalPathCh,ServerPath); } } fileup = null; // 删除subunsubfromsp目录下已经上传的文件文件 ft.deleFile(RWFileDir,""); // 断开服务器连接 ft.stop(RWFileDir); } } public boolean uploadFile(String RWFileDir, String filepathname,String LocalPath,String FtpPath) { boolean result = true; String message = ""; if (aftp != null) { System.out.println("正在上传文件" + filepathname + ",请等待...."); try { String fg = new String(LocalPath); int index = filepathname.lastIndexOf(fg); String filename = filepathname.substring(index + 1); File localFile = new File(filepathname); RandomAccessFile sendFile = new RandomAccessFile(filepathname, "r"); // sendFile.seek(0); // 改路径上传 filename = FtpPath + "ftp_" + filename.substring(LocalPath.length()-1, filename.length()); outs = aftp.put(filename); outputs = new DataOutputStream(outs); while (sendFile.getFilePointer() < sendFile.length()) { ch = sendFile.read(); outputs.write(ch); } outs.close(); sendFile.close(); message = "上传成功--(" + filepathname + "-->" + filename +")"; System.out.println(message); log(RWFileDir, message); } catch (IOException e) { message = "上传失败--(" + filepathname +")"; System.out.println(message); log(RWFileDir, message+e.toString()); result = false; } } else { result = false; } return result; } 我用sftp传大文件,ftp的没有试过 ftp协议上可能没有完全兼容,用serv-u/ftpd试试看啊。很多ftp服务器用ie ftp://user:pass@ip打不开的 java基础 请教字符串的编码处理 新人菜鸟求助 JGraph的中文教程 Java算法问题 谁能给一个控制台下的ant代码 J2SE支持写JSP? 请教:用java能不能实现小检索软件? 请教专家高手有什么好建议,谢谢 java能运行起来的最小软件包多少 如何在文件中插入一段信息,替代已有信息 竞选开发组长方案,请大家指教
String msg = "";
String hostname = getFtpSerIp();
int port = 21;
String uid = getFtpSerUser();
String pwd = getFtpSerPsw();
String RWFileDir = getLocalFileDir();// 文件目录
String LocalPathCh = getLocalFileDirChild();
String ServerPath = getFtpFileDir(); // 连接ftp服务器
FtpApplet ft = new FtpApplet();
ft.connect(RWFileDir, hostname, port, uid, pwd); // 上传文件
if (ft.aftp != null) {
File fdir = new File(RWFileDir);
String FileName = "";
File fileup = null;
int fdirlen = fdir.list().length;
for (int i = 0; i < fdirlen; i++) {
FileName = RWFileDir + (fdir.list())[i];
fileup = new File(FileName);
if(fileup.isFile() && FileName.lastIndexOf(".zip") > -1 )
{
//备份压缩文件
msg = ft.copyFile(FileName,getLocalFileDirCopy() + fileup.getName());
ft.log(RWFileDir, msg);//写入日志文件
System.out.println(msg);
//上传文件
ft.uploadFile(RWFileDir, FileName,LocalPathCh,ServerPath);
}
}
fileup = null; // 删除subunsubfromsp目录下已经上传的文件文件
ft.deleFile(RWFileDir,""); // 断开服务器连接
ft.stop(RWFileDir);
}
}
boolean result = true;
String message = "";
if (aftp != null) {
System.out.println("正在上传文件" + filepathname + ",请等待....");
try {
String fg = new String(LocalPath);
int index = filepathname.lastIndexOf(fg);
String filename = filepathname.substring(index + 1);
File localFile = new File(filepathname); RandomAccessFile sendFile = new RandomAccessFile(filepathname,
"r");
//
sendFile.seek(0);
// 改路径上传
filename = FtpPath + "ftp_"
+ filename.substring(LocalPath.length()-1, filename.length());
outs = aftp.put(filename);
outputs = new DataOutputStream(outs);
while (sendFile.getFilePointer() < sendFile.length()) {
ch = sendFile.read();
outputs.write(ch);
} outs.close();
sendFile.close(); message = "上传成功--(" + filepathname + "-->" + filename +")";
System.out.println(message);
log(RWFileDir, message);
} catch (IOException e) {
message = "上传失败--(" + filepathname +")";
System.out.println(message);
log(RWFileDir, message+e.toString());
result = false; }
} else {
result = false;
}
return result;
}