用sun的FTPClient 进行文件下载get的时候 ftpClient.get(remoteFileNameA)
;
抛异常
sun.net.ftp.FtpProtocolException: PORT :501 EPRT not allowed after EPSV ALL
at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:435)
at sun.net.ftp.FtpClient.get(FtpClient.java:550)
at util.FtpClientUtil.updown(FtpClientUtil.java:247)
at handler.ProviderHandler.providerMessageProc(ProviderHandler.java:100)
at com.ibm.adapter.handler.AdapterHandler.process(Unknown Source)
at com.ibm.handler.BaseHandler.executeRun(Unknown Source)
at com.ibm.handler.BaseHandler.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
程序:
...
private static FtpClient ftpClient;
...
public static String updown(String remoteFileNameA, String remoteFileNameB,
FileInfo fileInfo) throws Exception {
TelnetInputStream is = null;
TelnetOutputStream os = null;
FileOutputStream fos = null;
MD5 md = new MD5();
File inFile = new File(remoteFileNameA);
FileService filService = new FileService();
try {
// ftpClient.sendServer("quote PASV\r\n");
// ftpClient.sendServer("quote PORT\r\n");
ftpClient.sendServer("type c 935\r\n");
ftpClient.readServerResponse();
**is = ftpClient.get(remoteFileNameA);**
fos = new FileOutputStream(inFile);
try {
fileInfo.setStatus(2);
filService.downloadInsert(fileInfo);
} catch (Exception e) {
throw new RuntimeException("插入数据库失败!", e);
}
boolean flag2 = FtpClientUtil.connectserver(CBS_FTP_SERVER_IP, CBS_FTP_PORT,
CBS_FTP_USERNAME, CBS_FTP_PASSWD, CBS_FTP_DIRECTORY);
if (!flag2) {
System.out.println("服务器连接失败");
return "fail";
}
os = ftpClient.put(remoteFileNameB);
byte[] b = new byte[1024];
int c;
while ((c = is.read(b)) != -1) {
fos.write(b, 0, c);
os.write(b, 0, c);
}
try {
fileInfo.setStatus(1);
FileService.uploadUpdate(fileInfo);
} catch (Exception e) {
e.printStackTrace();
}
return md.getFileMD5String(inFile);
} catch (IOException e) {
throw new RuntimeException("文件上传或下载发生错误!", e);
} finally {
if (is != null)
is.close();
if (os != null)
os.close();
if (fos != null)
fos.close();
if (inFile.exists())
inFile.delete();
}
}
求大神给点建议。PS:有同样问题的:http://www.myexception.cn/j2se/16991.html也没有得到解决。我在别的ftp上是可以的,但是在我们自带的ftp上不行。可能是ftp模式设置上的问题。
欢迎选择我的课程,让我们一起见证您的进步~~