服务器是unix环境,怎么能浏览服务器目录?
以下是我写的代码,请帮忙看看。另请指教jsp写法public class Ftpload {
FtpClient ftpClient;
public Ftpload() {
} public void connectServer(){
//server:FTP服务器的IP地址;username:登录FTP服务器的用户名
//password:登录FTP服务器的用户名的口令;path:FTP服务器上的路径
ResourceBundle rb = ResourceBundle.getBundle("FtpUnload");
String server = rb.getString("IP");
int port = Integer.parseInt(rb.getString("Port"));
String username = rb.getString( "Username" );
String password = rb.getString( "Password" ); try{
ftpClient=new FtpClient(server,port); ftpClient.login(username, password);
System.out.println("login success!"); ftpClient.ascii();
}catch (IOException ex){
ex.printStackTrace();
}
} public void closeConnect(){
try{
ftpClient.closeServer();
}catch (IOException ex){
ex.printStackTrace();
}
} public void upload(String resfile, String objfile)
{ try {
TelnetOutputStream os=ftpClient.put(objfile);
File file_in=new File(resfile);
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();
}catch (IOException ex){
ex.printStackTrace();
}
} public void load(String resfile, String objfile)
{
int ch; try {
RandomAccessFile rFile = new RandomAccessFile(objfile,"rw");
rFile.seek(0);
TelnetInputStream tInput=ftpClient.get(resfile);
DataInputStream dInput = new DataInputStream(tInput); while ( (ch = dInput.read()) >= 0) {
rFile.write(ch);
}
dInput.close();
rFile.close(); }catch (IOException ex){
ex.printStackTrace();
}
}
}
以下是我写的代码,请帮忙看看。另请指教jsp写法public class Ftpload {
FtpClient ftpClient;
public Ftpload() {
} public void connectServer(){
//server:FTP服务器的IP地址;username:登录FTP服务器的用户名
//password:登录FTP服务器的用户名的口令;path:FTP服务器上的路径
ResourceBundle rb = ResourceBundle.getBundle("FtpUnload");
String server = rb.getString("IP");
int port = Integer.parseInt(rb.getString("Port"));
String username = rb.getString( "Username" );
String password = rb.getString( "Password" ); try{
ftpClient=new FtpClient(server,port); ftpClient.login(username, password);
System.out.println("login success!"); ftpClient.ascii();
}catch (IOException ex){
ex.printStackTrace();
}
} public void closeConnect(){
try{
ftpClient.closeServer();
}catch (IOException ex){
ex.printStackTrace();
}
} public void upload(String resfile, String objfile)
{ try {
TelnetOutputStream os=ftpClient.put(objfile);
File file_in=new File(resfile);
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();
}catch (IOException ex){
ex.printStackTrace();
}
} public void load(String resfile, String objfile)
{
int ch; try {
RandomAccessFile rFile = new RandomAccessFile(objfile,"rw");
rFile.seek(0);
TelnetInputStream tInput=ftpClient.get(resfile);
DataInputStream dInput = new DataInputStream(tInput); while ( (ch = dInput.read()) >= 0) {
rFile.write(ch);
}
dInput.close();
rFile.close(); }catch (IOException ex){
ex.printStackTrace();
}
}
}
我到底哪写错了?下面是我写的jsp
请帮忙啊各位大大<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="com.adtec.moia.web.ftp.*"%>
<html><body>
<%
FtpUnload ftp = new FtpUnload();
String infile = "/home/test/tmp/t.txt";
String outfile = "C:/tt.txt";
try{
ftp.connectServer();
ftp.load(infile,outfile );
}catch(Exception e){
out.println(e.getMessage());
}finally{
ftp.closeConnect();
} out.println("<Script>window.location.href=\"ftpsucc.jsp\";</Script>");
%>
</body>
</html><%@ page contentType="text/html; charset=GBK" %>
<%@ page import="com.adtec.moia.web.ftp.*"%>
<html><body>
<%
FtpUnload ftp = new FtpUnload();
String resfile = request.getParameter("infile");
resfile = new String(resfile.getBytes("8859_1"), "GB2312");
String objfile = "/home/test/tmp/t.txt"; try{
ftp.connectServer();
ftp.upload(resfile,objfile);
}catch(Exception e){
out.println(e.getMessage());
}finally{
ftp.closeConnect();
}%>
</body>
</html>