请教高手:FTP问题

kingaliu 2001-11-26 10:54:09
我写了一个bean,然后在jsp中实现文件的下载,但未成功,不能下载到客户端,只下到了服务器上,请问这是什么原因?我的脚本如下:
Bean脚本:

package htclass;

import sun.net.ftp.*;
import sun.net.*;
import java.net.*;
import java.io.*;

public class FtpDownFile{
String server="202.98.46.109";//输入的FTP服务器的IP地址
String user="lrh";//登录FTP服务器的用户名
String password="lrh";//登录FTP服务器的用户名的口令
String path="ftpfile";//FTP服务器上的路径
String ErrMsg;
public boolean FileDown(String SourFile,String DecFile)
{
try
{
FtpClient ftpClient=new FtpClient();//创建FtpClient对象
ftpClient.openServer(server);//连接FTP服务器
ftpClient.login(user, password);//登录FTP服务器
if (path.length()!=0) ftpClient.cd(path);
ftpClient.binary();
TelnetInputStream is=ftpClient.get(SourFile);
File file_out=new File(DecFile);
FileOutputStream os=new FileOutputStream(file_out);
byte[] bytes=new byte[1024];
int c;
while ((c=is.read(bytes))!=-1)
{
os.write(bytes,0,c);
}
is.close();
os.close();
ftpClient.closeServer();
return true;
}catch (IOException ex)
{
System.out.println("Error!!\n"+ex.getMessage());
ErrMsg=ex.getMessage();
return false;
}
}

public String GetErrMsg()
{
return ErrMsg;
}
}


jsp脚本:

<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="File" class="htclass.FtpDownFile" scope="page"/>

<html>

<head>
<title>FTP文件下载测试</title>
</head>

<%@ page language="java"%>
<%
if(File.FileDown("item.sql","item.txt"))
out.print("文件下载成功!");
else
out.print(File.GetErrMsg());
%>
</html>
...全文
45 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧