501 port not allow after EPSV ALL, active mode off错误
用sun的ftp包连接IBM aix服务器抛如下错误:
501 port not allow after EPSV ALL, active mode off
原因:
ftp要改为被动passtive模式.
解决方法:
使用第三方包edtftpj-1.5.1.jar连接服务器,在连接前设置模式为passtive
Demo
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package app4;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPMessageCollector;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;
import java.util.Date;
import java.io.File;
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPMessageCollector;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;
import java.util.Date;
import java.io.File;
public class Demo {
/**
* Log stream
*/
private static Logger log = Logger.getLogger(Demo.class);
/**
* Log stream
*/
private static Logger log = Logger.getLogger(Demo.class);
public static void main(String[] args) {
// we want remote host, user name and password
// if (args.length < 3) {
// usage();
// System.exit(1);
// }
// if (args.length < 3) {
// usage();
// System.exit(1);
// }
// assign args to make it clear
String host = "localhost";//args[0];
String user = "lijun2";//args[1];
String password = "836301";//args[2];
String host = "localhost";//args[0];
String user = "lijun2";//args[1];
String password = "836301";//args[2];
Logger.setLevel(Level.ALL);
FTPClient ftp = null;
try {
// set up client
log.info("Connecting");
// set up client
log.info("Connecting");
ftp = new FTPClient(host);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);
// login
log.info("Logging in");
ftp.login(user, password);
log.info("Logging in");
ftp.login(user, password);
// set up passive ASCII transfers
log.debug("Setting up passive, ASCII transfers");
ftp.setConnectMode(FTPConnectMode.PASV);
ftp.setType(FTPTransferType.BINARY);
log.debug("Setting up passive, ASCII transfers");
ftp.setConnectMode(FTPConnectMode.PASV);
ftp.setType(FTPTransferType.BINARY);
// get directory and print it to console
log.debug("Directory before put:");
String[] files = ftp.dir(".", true);
for (int i = 0; i < files.length; i++)
log.debug(files[i]);
log.debug("Directory before put:");
String[] files = ftp.dir(".", true);
for (int i = 0; i < files.length; i++)
log.debug(files[i]);
// copy file to server
System.out.println(new Date());
log.info("Putting file");
File loadfile = new File("a.ISO");
ftp.put("a.ISO", "a.ISO");
System.out.println(new Date());
// get directory and print it to console
log.debug("Directory after put");
files = ftp.dir(".", true);
for (int i = 0; i < files.length; i++)
log.debug(files[i]);
System.out.println(new Date());
log.info("Putting file");
File loadfile = new File("a.ISO");
ftp.put("a.ISO", "a.ISO");
System.out.println(new Date());
// get directory and print it to console
log.debug("Directory after put");
files = ftp.dir(".", true);
for (int i = 0; i < files.length; i++)
log.debug(files[i]);
// copy file from server
// log.info("Getting file");
// ftp.get("2005.doc" + ".copy", "2005.doc");
// log.info("Getting file");
// ftp.get("2005.doc" + ".copy", "2005.doc");
// delete file from server
//log.info("Deleting file");
// ftp.delete("test.txt");
//log.info("Deleting file");
// ftp.delete("test.txt");
// get directory and print it to console
// log.debug("Directory after delete");
files = ftp.dir("", true);
for (int i = 0; i < files.length; i++)
log.debug(files[i]);
// log.debug("Directory after delete");
files = ftp.dir("", true);
for (int i = 0; i < files.length; i++)
log.debug(files[i]);
// Shut down client
log.info("Quitting client");
ftp.quit();
log.info("Quitting client");
ftp.quit();
String messages = listener.getLog();
log.debug("Listener log:");
log.debug(messages);
log.debug("Listener log:");
log.debug(messages);
log.info("Test complete");
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void usage() {
System.out.println("Usage: Demo remotehost user password");
}
}
}