java - FtpRemoteFileTemplate checks if remote file exists but cannot retrieve it -


i have ftpremotefiletemplate:

@autowired private ftpremotefiletemplate ftptemplate; 

and use in way:

if (ftptemplate.exists(fileabspath)) {     return getremotefileasbytearray(fileabspath); } 

where getremotefileasbytearray is

private byte[] getremotefileasbytearray(string absolutefilename) {     return ftptemplate.execute(session -> ioutils.tobytearray(session.readraw(absolutefilename))); } 

the statement ftptemplate.exists(fileabspath) works , correctly returns true, ftptemplate.execute(session -> ioutils.tobytearray(session.readraw(absolutefilename))) after while throws exception:

org.springframework.messaging.messagingexception: failed execute on session; nested exception java.io.ioexception: failed obtain inputstream remote file /xxx/xxx/foo.jpg: 425     @ org.springframework.integration.file.remote.remotefiletemplate.execute(remotefiletemplate.java:419) ~[spring-integration-file-4.2.4.release.jar:?]     @ xxx.xxx.service.impl.imageserviceftpimpl.getremotefileasbytearray(imageserviceftpimpl.java:91) ~[classes/:?]     @ xxx.xxx.service.impl.imageserviceftpimpl.getimage(imageserviceftpimpl.java:64) [classes/:?]     @ xxx.xxx.service.impl.abstractimageservice.getoriginaltransitimage(abstractimageservice.java:22) [classes/:?]     @ xxx.xxx.service.rest.servicecontroller.getoriginaltransitimage(servicecontroller.java:138) [classes/:?]     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) ~[?:1.8.0_71]     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) ~[?:1.8.0_71]     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) ~[?:1.8.0_71]     @ java.lang.reflect.method.invoke(method.java:497) ~[?:1.8.0_71]     @ org.springframework.web.method.support.invocablehandlermethod.doinvoke(invocablehandlermethod.java:222) [spring-web-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:137) [spring-web-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlermethod(requestmappinghandleradapter.java:814) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:737) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:959) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:969) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:860) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ javax.servlet.http.httpservlet.service(httpservlet.java:687) [javax.servlet-api-3.1.0.jar:3.1.0]     @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:845) [spring-webmvc-4.2.4.release.jar:4.2.4.release]     @ javax.servlet.http.httpservlet.service(httpservlet.java:790) [javax.servlet-api-3.1.0.jar:3.1.0]     @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:812) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1669) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:316) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.invoke(filtersecurityinterceptor.java:126) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.dofilter(filtersecurityinterceptor.java:90) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.access.exceptiontranslationfilter.dofilter(exceptiontranslationfilter.java:114) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.session.sessionmanagementfilter.dofilter(sessionmanagementfilter.java:122) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.authentication.anonymousauthenticationfilter.dofilter(anonymousauthenticationfilter.java:111) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter.dofilter(securitycontextholderawarerequestfilter.java:169) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.savedrequest.requestcacheawarefilter.dofilter(requestcacheawarefilter.java:48) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.authentication.www.basicauthenticationfilter.dofilterinternal(basicauthenticationfilter.java:158) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) [spring-web-4.2.4.release.jar:4.2.4.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:120) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.header.headerwriterfilter.dofilterinternal(headerwriterfilter.java:64) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) [spring-web-4.2.4.release.jar:4.2.4.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:91) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.context.request.async.webasyncmanagerintegrationfilter.dofilterinternal(webasyncmanagerintegrationfilter.java:53) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) [spring-web-4.2.4.release.jar:4.2.4.release]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ xxx.xxx.service.util.simplecorsfilter.dofilter(simplecorsfilter.java:26) [classes/:?]     @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:213) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:176) [spring-security-web-4.0.3.release.jar:4.0.3.release]     @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:346) [spring-web-4.2.4.release.jar:4.2.4.release]     @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:262) [spring-web-4.2.4.release.jar:4.2.4.release]     @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1652) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:585) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:143) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:577) [jetty-security-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:223) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1127) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:515) [jetty-servlet-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:185) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:1061) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:141) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection.java:215) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection.java:110) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:97) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.server.handle(server.java:499) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.httpchannel.handle(httpchannel.java:311) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.server.httpconnection.onfillable(httpconnection.java:257) [jetty-server-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.io.abstractconnection$2.run(abstractconnection.java:544) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:635) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]     @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:555) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]     @ java.lang.thread.run(thread.java:745) [?:1.8.0_71] caused by: java.io.ioexception: failed obtain inputstream remote file /xxx/xxx/foo.jpg: 425     @ org.springframework.integration.ftp.session.ftpsession.readraw(ftpsession.java:96) ~[spring-integration-ftp-4.2.4.release.jar:?]     @ xxx.xxx.service.impl.imageserviceftpimpl.lambda$0(imageserviceftpimpl.java:91) ~[classes/:?]     @ org.springframework.integration.file.remote.remotefiletemplate.execute(remotefiletemplate.java:410) ~[spring-integration-file-4.2.4.release.jar:?]     ... 76 more 

from filezilla i'm able retreive same file same computer.

where i'm getting wrong?

ftp requires 2 separate channels communication. command channel working you able file existence status server. if trying communication in active mode, requires server initiate connection system , in case chances firewall block such connection, causing io exception.

to overcome issue can change client mode passive. in config, change clientmode 2. or if have hold of ftpclient instance, can use client.enterlocalpassivemode();.

passive_local_data_connection_mode = 2


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -