使用 java 推送文件到 ftp 服务器和拉取文件的时候 ,报了这个错误:
Caused by: java.lang.NoSuchMethodError: org.apache.commons.net.ftp.FTPClient.setControlEncoding(Ljava/lang/String;)V
at cn.hutool.extra.ftp.Ftp.init(Ftp.java:135)
at cn.hutool.extra.ftp.Ftp.init(Ftp.java:107)
at cn.hutool.extra.ftp.Ftp.<init>(Ftp.java:98)
at cn.hutool.extra.ftp.Ftp.<init>(Ftp.java:78)
at cn.hutool.extra.ftp.Ftp.<init>(Ftp.java:65)
at com.linkcm.dss.core.util.FTPUtil.sendFile(FTPUtil.java:509)
at com.linkcm.dss.zhuhailocal.service.impl.ZhDisasterReportServiceImpl.init(ZhDisasterReportServiceImpl.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:354)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:305)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 74 more
发现相关依赖包引入是这个版本:
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>20030805.205232</version>
</dependency>
这个版本缺少一些方法,改成这版本就不会报错了。
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>