java ftp下载出现_JAVA FTPClient 文件下载时关于设置模式出的异常

用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模式设置上的问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值