我的代码中的端口号必须与我尝试连接的 FTP 服务器(在本例中为本地主机)使用的端口号完全相同吗?
public class FTP {
public static void main(String args[]) {
FTPClient ftpc = new FTPClient();
try {
ftpc.connect("127.0.0.1",49961);
ftpc.login("username", "password");
System.out.println("Connected");
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("NOT Connected (socketERR) ");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("NOT Connected (ioERR) ");
}
}
}
错误日志:
java.net.ConnectException:连接被拒绝:在 java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) 在 java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) 在 java.net.DualStackPlainSocketImpl.connect0(Native Method) 连接.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket .connect(Unknown Source) at org.apache.commons.net.SocketClient.connect(SocketClient.java:182) at org.apache.commons.net.SocketClient.connect(SocketClient.java:203) at com.testftp.FTP .main(FTP.java:23) 未连接 (socketERR)