连接FTP时报错,急救!!
执行到ftp.connect(ftpIP)进报的错,ftpIP是有值是IP+ ": "+端口
//FTP连接
public boolean connectFTP(){
try {
ftp = new FTPClient();
if(ftpPort.equals( " ")){
ftp.connect(ftpIP);
}
boolean blogin = ftp.login(ftpUser,ftpPassword);
if (!blogin) {
System.out.println( "FTP
连接失败: "+ftpIP);
ftp.disconnect();
ftp = null;
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
System.out.println( "FTP连接失败: "+ftpIP);
}
return false;
}
java.net.InetAddress.getAllByName0(InetAddress.java:591)
java.net.InetAddress.getAllByName0(InetAddress.java:560)
java.net.InetAddress.getByName(InetAddress.java:492)
java.net.Socket. <init> (Socket.java:121)
at org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:53)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:162)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:250)
at JavaAgent.connectFTP(JavaAgent.java:432)
------解决方案--------------------没人知道吗,急啊!!!!!!!
------解决方案--------------------import sun.net.ftp.*;
import java.io.*;
import
java.io.IOException;
import java.util.StringTokenizer;
import sun.net.ftp.*;
import java.util.ArrayList;
import sun.net.TelnetOutputStream;
public class ftpClient {
public ftpClient() {
}
FtpClient client;
private String host= "135.64.160.151 ";//FTP服务器IP
private String username= "anonymous ";//FTP用户名字
private String password= " ";//FTP密码
private String path = "/test "; //文件要放哪个目录
private int port = 21; //FTP端口
/**
* 连接服务器方法
*/
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(
BufferedReader 有关问题