sun.net.*,在jdk/lib中是不带的,好像在jre中有。在jre/lib/jsse.jar中包含了这个包。
解决方案 »
- 关于打字游戏的问题
- socket客户端如何等到服务端接受处理完成并返回处理结果后再往下进行(同步问题)
- 怎么才能让eclipse运行的时候不在eclipse的console显示结果呢?
- 怎样在控制台执行下面的代码
- 关于JOptionPane的showInputMessage的问题
- 如何修改JDialog中标题栏的颜色
- javax.servlet.http 问题?
- 名字问题[问问]
- applet放在apache server上可以,为什么在iis下就不行了呢?
- 关于垃圾收集器的一个问题
- 我在调用FtpClient类的put(filename)函数时,报错???同样的代码为什么有的计算机上可以执行,有的就报异常?高分求救!
- 为什么这个简单的程序都出错?
import java.io.*;
import sun.net.ftp.*;
import sun.net.*;public class FtpClientEnd
{
FtpClient aFtpClient=null;
private String hostName=null;
private String userName=null;
private String userPass=null;
private String remoteFilePath=null;
private String localFilePath=null;
private int try_time=3;
public FtpClientEnd(String hostName,String userName,String userPass,String remoteFilePath,String localFilePath)
{
this.hostName=hostName;
this.userName=userName;
this.userPass=userPass;
this.remoteFilePath=remoteFilePath;
this.localFilePath=localFilePath;
}
public boolean connectServer()
{
if(hostName==null || hostName.equals(""))
{
System.out.println("ftp hostname can't be blank.");
return false;
}
System.out.println("Connecting to host: "+hostName+"...");
try
{
aFtpClient=new FtpClient(hostName);
aFtpClient.login(userName,userPass);
aFtpClient.binary();
}
catch(FtpLoginException e)
{
//System.out.println("无权限访问ftp主机.");
System.out.println("not privilidged to access ftp host.");
return false;
}
catch(IOException e)
{
//System.out.println("连接ftp主机失败.");
System.out.println("fail to connect to ftp host.");
return false;
}
catch(SecurityException e)
{
//System.out.println("无权限连接ftp主机.");
System.out.println("not privilidged to connect to ftp host.");
return false;
}
//System.out.println("ftp主机连接成功.");
System.out.println("successful to connect to ftp host.");
return true;
} public boolean upLoadFile(String fileName)
{
boolean connected=connectServer();
int i=try_time;
while(i>0)
{
if(connected==false)
i--;
else
break;
}
if(i<=0)
return false; RandomAccessFile sendFile=null;
TelnetOutputStream out=null;
DataOutputStream output=null;
int byteData;
try
{
sendFile = new RandomAccessFile(localFilePath+fileName,"r");
}
catch(IOException e)
{
//System.out.println("ftp读本地文件错误。");
System.out.println("ftp read local file error.");
closeCon();
return false;
}
try
{
aFtpClient.cd(remoteFilePath);
}
catch(IOException e)
{
//System.out.println("远程路径错误。");
System.out.println("ftp remote path error.");
e.printStackTrace();
closeCon();
return false;
}
try
{
//System.out.println("正在发送文件:"+fileName+"...");
System.out.println("Sending file: "+fileName+"...");
sendFile.seek(0);
System.out.println("a");
out=aFtpClient.put(fileName);
System.out.println("b");
output=new DataOutputStream(out);
System.out.println("c");
while(sendFile.getFilePointer?-焔?G^F3/?鞛V'8{?"奁WH?4嬊?油?
试一试
FtpClient(String string, int int1)再就是,我推荐给你一个包,比较省事的com.oroinc.net.ftp