Apache commons-net

Hi
I was using apache commons-net to FTP some files to an FTP server.
I was able to login to the server. I want to know How can I move out from my root directory. Is it possible using apche coomons-net. The working directory displayed is only /home/myname.
Thanks
Prabhath Nair

If you want to move to a sub-directory within your current root then could it possibly be the changeWorkingDirectory() command?
P.S. You wont be able to move to some directory such as /etc because FTP servers constrain you to stay within a fixed root directory. Often, the home directory of the login name.

Similar Messages

  • Connect to FTP site with Apache commons net FTP client through Proxy

    Hello,
    I am trying to run this simple code to connect to FTP site through a proxy.
    import org.apache.commons.net.ftp.FTP;
    import org.apache.commons.net.ftp.FTPClient;
    public class MyTest {
    public static void main(String[] args) {
    String ftpHostName = "ftp.xxx.com";
    int ftpPort = 21;
    String ftpUserName = "myUserName";
    String ftpPassword = "myPassword";
    System.setProperty("socksProxyHost" ,"10.148.0.131");
    System.setProperty("socksProxyPort", "1080");
    FTPClient ftpClient = new FTPClient();
    try {
    System.out.println("connecting");
    ftpClient.connect(ftpHostName, ftpPort);
    System.out.println("connected");
    System.out.println("loging in");
    boolean successLogin = ftpClient.login(ftpUserName, ftpPassword);
    if(successLogin)
    System.out.println("success login");
    else
    System.out.println("fail login");
    catch (Exception e) {
    e.printStackTrace();
    finally {
    try {
    System.out.println("loging out");
    ftpClient.logout();
    System.out.println("disconecting");
    ftpClient.disconnect();
    catch (Exception e) {
    e.printStackTrace();
    I am getting the following error:
    C:\temp\ftp\test>java.exe -cp ./commons-net-ftp-2.0.jar;. MyTest connecting
    java.net.SocketException: Malformed reply from SOCKS server
    at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:87)
    at java.net.SocksSocketImpl.connectV4(SocksSocketImpl.java:265)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:437)
    at java.net.Socket.connect(Socket.java:519)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:176)
    at MyTest.main(MyTest.java:23)
    loging out
    java.lang.NullPointerException
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:471<ftp://FTP.java:471>)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:534<ftp://FTP.java:534>)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:583<ftp://FTP.java:583>)
    at org.apache.commons.net.ftp.FTP.quit(FTP.java:794<ftp://FTP.java:794>)
    at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:697)
    at MyTest.main(MyTest.java:39)
    I am able to do this using a different FTP client library, ftp4j-1.5.1<ftp://ftp4j-1.5.1> using the following code:
    import it.sauronsoftware.ftp4j.FTPClient;
    import it.sauronsoftware.ftp4j.connectors.SOCKS4Connector;
    public class MyTestFtp4J {
    public static void main(String[] args) {
    String ftpHostName = "ftp.xxx.com";
    int ftpPort = 21;
    String ftpUserName = "myUserName";
    String ftpPassword = "myPassword";
    FTPClient ftpClient = new FTPClient();
    ftpClient.setConnector(new SOCKS4Connector("10.148.0.131", 1080));
    try {
    System.out.println("connecting");
    ftpClient.connect(ftpHostName, ftpPort);
    System.out.println("connected");
    System.out.println("loging in");
    ftpClient.login(ftpUserName, ftpPassword);
    System.out.println("success login");
    catch (Exception e) {
    e.printStackTrace();
    finally {
    try {
    System.out.println("disconecting");
    ftpClient.disconnect(true);
    catch (Exception e) {
    e.printStackTrace();
    So I know the proxy settings are correct.
    The java version I used to compile and run my apps is 1.6.0_06 Does anyone can help figure out what is wrong when I use the Apache commons net FTP client?
    Thank you
    Jon

    Is the old AirPort Extreme base station (AEBS)
    configured so that the option to distribute IP
    addresses is DISABLED? If so, configure the new AEBS
    to act as a bridge.
    Are you suggesting I use a set-up with TWO AEBSs? Set up a bridge (not sure how) and then use the old AEBS to connect to the DSL modem and broadcast to the new Extreme which will then be the router to the other computers on the network?
    Do you have any port mapping or default host enabled
    on the old AEBS?
    I do not understand, not do I see these options in the Base Station utitlity; perhaps they are in the FTP options--but that, I'm sorry to say, is not obvious to my inspection.
    Duane, can you give me a few more basic instructions? Thanks
    iMac 17    

  • Apache Commons Net - Retrieve File - Extension, Compare , Move - FTP Server

    Dear All,
    I am using Apache Commons net FTP Library for FTP Operations. I had a few doubts
    1) I like to retrieve ftp files only with some extensions like *.txt or *.jpg etc. How can we retrieve files with specifying file extension?
    2) I need to compare the FTP Files with the local files before downloading from the FTP Server?
    3) I need to move files from the ftp server to local directory. Is there is anyway to move the files rather than first retrieve files from the FTP Server and then deleting the file in the FTP Server using FTP delete()
    Thanks,
    J.Kathiresan

    1) I like to retrieve ftp files only with some
    extensions like *.txt or *.jpg etc. How can we
    retrieve files with specifying file extension?
    List the files and then filter the list to those that you want to process.
    2) I need to compare the FTP Files with the local
    files before downloading from the FTP Server?Think about this one! To compare two files you nead to read both. If you do this on the client then you will have to copy the file from the server first!
    >
    3) I need to move files from the ftp server to local
    directory. Is there is anyway to move the files
    rather than first retrieve files from the FTP Server
    and then deleting the file in the FTP Server using
    FTP delete()What is wrong with copy then delete?

  • Apache Commons Net deployment fails to resolve, JDev classpath question

    I wrote a wrapper to apache's most recent version of commons-net package (version 1.4.1) to allow me to execute FTP services from an Oracle 9i2 database. After adding the common-net .jar file to the JDev libraries, and including this library in my project, I debugged the code in Jdeveloper, then deployed to the Oracle 9i2 server. However, many classes of the of the common-net (and my code) failed to resolve in the database.
    After downloading open source product DependencyFinder, and running against the Commons-net .jar file, I found that some packages were dependent on the Apache ORO regexp package. The ORO package, as far as I can tell, is not in any classpath that my JDev project uses. There is listed in the JDev libraries, a library called Apache Regexp, but I did not include that in the project, either.
    After I downloaded the ORO package from Apache, added it to JDev's libraries, included it in my project, and added the ORO library to the list of classes to deploy (using the loadjava deployment profile), deployment to Oracle 9i2 of the my classes, the commons-net classes, and the ORO classes properly resolved.
    My question is: Why did my application work under JDeveloper? How and where did it find the ORO classes?
    The version of Java under which JDeveloper is running, and the version being used as the compiler for this project, is a new installation of JDK1.4.2_10.

    Since the commons net 1.4.1 is compatible with jdk 1.3.1, I should only need to use loadjava on the .jar file. In fact, that works, given that there is no failure on load due to incompatible .jar or .class files structure.
    But, I've just solved this part of the problem. The commons net 1.4.1 is dependent on, but does not include the Apache ORO library. Once the ORO library was deployed to Oracle 9i2, all common net 1.4.1 classes were resolved.
    The "problem" is with JDeveloper. Without including the ORO library in the JDeveloper application, or in the classpath, it worked under JDeveloper -- the more surprising since I had never downloaded the ORO library from Apache. Only after downloading ORO, explicitly defining ORO to JDeveloper, and including ORO as a library in my JDeveloper project, did the deployment of the application to Oracle 9i2 succeed (though the application always executed successfully under JDeveloper).

  • Apache Commons Net FTP : ListFiles not displaying all dirs and files

    So I am doing this:
    FTPClient f = new FTPClient();
    f.connect("foo.bar.com");
    boolean login = f.login("User","Pass");
    FTPFile[] list = f.listFiles();
    When I doing a "list.length" I get 2. When I list it out it just shows that it retrieved the directories only. I know there are more files there....
    Here is the wierd thing. When I manually FTP from this Windows box and do a dir I only get the two listings. When I FTP from my linux box I get the full directory listing (those two directories and more files).
    Any ideas as to why I am not picking these up?
    Thanks,
    Michael

    File permissions / hidden / visible etc?

  • Org/apache/commons/fileupload/FileUploadException

    hia all,
    i am trying to save an image using <html:file> tag in jsp pages
    usig struts
    Before doing any save action,i am getting this error
    any one know
    thanx
    8:41:52,714 ERROR [Engine] StandardWrapperValve[FrontController]: Servlet.service() for servlet FrontController threw exception
    java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException
         at java.lang.Class.getDeclaredConstructors0(Native Method)
         at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
         at java.lang.Class.getConstructor0(Class.java:1762)
         at java.lang.Class.newInstance0(Class.java:276)
         at java.lang.Class.newInstance(Class.java:259)
         at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:145)
         at org.apache.struts.util.RequestUtils.getMultipartHandler(RequestUtils.java:564)
         at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:430)
         at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:798)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:205)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
         at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
         at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
         at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:150)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
         at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
         at java.lang.Thread.run(Thread.java:536)

    Commons-fileupload.jar is already in the web-inf/lib.
    Is there another solution?Add the jar to the server's shared/lib or common/lib. Did you really need to ask this on an old thread?

  • JSP error java.lang.NoClassDefFoundError: org/apache/commons/fileupload/Fil

    I'm rather new to jsp. I'm using myeclipse and I'm deploying my site on tomcat. I've been slowly working away on the errors in my log files. Most of the problems that I've run into have been missing jar files. The log error that I'm stuck on follows:
    10:14:40,359 ERROR [Faces Servlet]:253 - Servlet.service() for servlet Faces Servlet threw exception
    java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUpload
         at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:115)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at com.wolverinecrane.view.util.SecurityFilter.doFilter(SecurityFilter.java:77)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
         at java.lang.Thread.run(Thread.java:595)
    In my buildpath I have commons-fileupload-1.0.jar which includes org.apache.commons.fileupload which has the class FileUpload.class in it.
    Any help on what may be going wrong here would be appreciated.
    Dan

    Solved:
    http://javalive.com/modules/newbb/viewtopic.php?topic_id=355&post_id=1013&order=0&viewmode=flat&pid=0&forum=4#forumpost1013

  • HTTPS over Apache commons HttpsClient API

    I have an EJB (running on Weblogic 6.1) that currently uses java.net.URL to connect to an Apache webserver to read some data. The problem with this is that I am unable to set a timeout on the URL connection. To get around this problem, I have rewritten it using the Apache Commons' HttpClient package (version 2.0 alpha 2).
    My problem is that whenever I try to connect, I get an exception:
    javax.net.ssl.SSLHandshakeException: FATAL Alert:HANDSHAKE_FAILURE - The handshake handler was unable to negotiate an acceptable set of security parameters.
    It's very frustrating, because the EJB works fine when I use the java.net.URL class. So I am lead to believe that I have SSL set up and working correctly. If not, how is the URL class able to connect?
    Since the URL I must connect to is a CGI, I used the GetMethod class as shown below...
    ----- snip --------
    String urlText = "https://my.host.name/path/to/some.cgi?queryString";
    URI myUrl = new URI( urlText );
    Protocol myProtocol = Protocol.getProtocol(myUrl.getScheme());
    HttpConnection connection = new HttpConnection(myUrl.getHost(), 443, myProtocol);
    connection.setSoTimeout(10000);
    HttpState state = new HttpState();
    GetMethod method = new GetMethod(myUrl.toString());
    // This is where the exception is thrown.
    method.execute(state, connection);
    What am I doing wrong?

    OK, nevermind. I solved the problem.
    For the record, the problem is the order of jars in my weblogic server classpath. I found a related problem in a Weblogic newsgroup that suggested putting the JSSE jars in the classpath before the weblogic.jar. So I tried that and now everything works.
    It is still very odd that this problem only pops up when I use the HttpClient package, not when using java.net.URL.

  • Commons net and retrieve complete dir structure

    Hi everybody,
    I'm using commons net from apache to connect and download files from a FTP site.
    I have a question: is there any easy (and quick above all...) function to get the complete directory structure of FTP site without using recursively the listFiles() method, which takes a LOT of time?
    I only need to syncronize a local dir structure to the FTP one. I don't need to download any file. Many thanks for your help.

    1) I like to retrieve ftp files only with some
    extensions like *.txt or *.jpg etc. How can we
    retrieve files with specifying file extension?
    List the files and then filter the list to those that you want to process.
    2) I need to compare the FTP Files with the local
    files before downloading from the FTP Server?Think about this one! To compare two files you nead to read both. If you do this on the client then you will have to copy the file from the server first!
    >
    3) I need to move files from the ftp server to local
    directory. Is there is anyway to move the files
    rather than first retrieve files from the FTP Server
    and then deleting the file in the FTP Server using
    FTP delete()What is wrong with copy then delete?

  • FTPS using JDK 1.4, Apache Commons, JScape, JSh

    I want to write a stand-alone Java program (not web based, it is Java main class), I want to do FTPS (FTP over SSL) to a remote box outside the firewall. Following are my questions:
    1. Does JDK 1.4 support it?
    2. Does JDK 1.5 support it?
    3. Does Apache Commons commons-net-1.4.1.jar support it in JDK 1.4?
    If not, I may look into using JScape or JSh.
    Any recommendation on how to write FTPS using JDK package 1.4?
    I was thinking of using JDK 1.4 as follows, however do not know if it will support FTPS. However, JDK support is rudimentary.
    URL url = new URL("ftp://user01:[email protected]/README.txt;type=i");
    URLConnection urlc = url.openConnection();
    InputStream is = urlc.getInputStream(); // To download
    OutputStream os = urlc.getOutputStream(); // To upload
    I have used Apache commons for FTP in the past, but it was not FTPS. I do not think that Apache commons supports FTPS. Please let me know, if Apache commons can also support FTPS.
    As far as I know, JScape supports FTPS.
    Any recommendation, or suggestion will be helpful.

    Hi, i'm with the issue. If you take a look at [http://commons.apache.org/net] you'll see that in version 2.0 ftps is supported. But, up to now i couldn't connect to the server, XFB Gateway in my case, it's difficult to find examples and documentation about it.
    Did you you figure out how to do it? If so, please post some help.

  • Commons-Net  FTPS : Trust All Certificates?

    Hi,
    I am using apache's common-net 3.1 to try and establish an ftps connection(port 990). I am trying to ftp directly into another computer (long story of why I have to do it this way, but i do). When I try to connect, I get a few security errors. Is there anyway to allow/trust all certificates or disable certificate verification?
    Any help or suggestions (on maybe another library that can do this?) are greatly appreciated!
    Edited by: 943461 on Jun 28, 2012 10:16 AM

    Why are you using FTPS if you don't want it to be secure?
    Solve the real problem: import the certificates.

  • I am trying to use apache commons fileupload and get this error

    I am using tomcat 5.5 as application server and JDK 1.6,
    does anybody have idea how to resolve this error ?
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.security.AccessControlException: access denied (java.util.PropertyPermission java.io.tmpdir read)
         java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
         java.security.AccessController.checkPermission(AccessController.java:546)
         java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
         java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
         java.lang.System.getProperty(System.java:652)
         org.apache.commons.fileupload.disk.DiskFileItem.getTempFile(DiskFileItem.java:611)
         org.apache.commons.fileupload.disk.DiskFileItem.getOutputStream(DiskFileItem.java:556)
         org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
         project.UploadFiles.processRequest(UploadFiles.java:48)
         project.UploadFiles.doPost(UploadFiles.java:107)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
         sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         java.lang.reflect.Method.invoke(Method.java:597)
         org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
         java.security.AccessController.doPrivileged(Native Method)
         javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
         org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
         org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

    Make sure that the servlet has permissions to write to that directory. I've hit that snag before, and on linux I set the permissions to nobody nobody 775.
    Good luck,
    Krista

  • Attachements with apache commons fileupload

    I'm using:
    http://commons.apache.org/fileupload/
    to write file on server side (Tomcat running on Windows with XP or 2003).
    I'm sending data to servlet with doPost() as follows:
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                DiskFileItemFactory factory = new DiskFileItemFactory();
                factory.setSizeThreshold(4096);
                factory.setRepository(new File("test"));
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(1000000);
                List fileItems = upload.parseRequest(request);
                Iterator i = fileItems.iterator();
                String comment = ((FileItem) i.next()).getString();
                FileItem fi = (FileItem) i.next();
                String fileName = fi.getName();
                // db
                fi.write(new File("C:/", fileName));
            } catch (Exception ex) {
                out.print(ex.getMessage());
            out.close();
        }but it's response is:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Servlet execution threw an exception
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    root cause
    java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
         org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
         org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
         Upload.doPost(Upload.java:69)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    root cause
    java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
         java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
         org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
         org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
         Upload.doPost(Upload.java:69)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
    Apache Tomcat/6.0.16don't know why.. any ideas?

    java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStreamThe mentioned class is missing in the runtime classpath.
    Add it (in this specific case, the JAR file with the mentioned class) to the classpath and the problem will disappear.
    This class is part of Commons IO. Read the dependencies page at FileUpload user guide which JAR's you all need.

  • Problems with Apache Commons Validator

    Hello there,
    I got a quiet big problem using the a.m. validation framework. When defining a validation rule for a property like this:
    <formset>
    <form name="testForm">
    <field property="firstName" depends="isEmail">
    <arg0 key="testForm.firstname"/>
    </field>
    </form>
    </formset>
    and instanciating my validator as follows:
    Validator validator = new Validator(resources, "testForm");
    validator.setParameter(Validator.BEAN_PARAM, name);
    everything works fine! I get a correct ValidatorResult object with a correct validation value.
    But as soons as I define a second Validation on the same property like this:
    <formset>
    <form name="testForm">
    <field property="firstName" depends="isEmail,isBlankOrNull">
    <arg0 key="testForm.firstname"/>
    </field>
    </form>
    </formset>
    Nothing works anymore. When iterating over the ValidatorResults object I only get one ValidatorResult object for "isEmail" with a wrong validation value. There should be two working ValidatorResult objects for "isEmail" and "isBlankOrNull"?!?!
    Are two validation method in the depends-Attribute not allowed (although it is defined in the standard)?
    You can assume, that the used validator class is conform to the given org.apache.commons.TestValidator!
    For any help, thx in advance!
    Greets
    CN

    Hey Aaron,
    Could you post your code for your <field>...</field>?
    Here is an example from: http://www.jsn-server3.com/struts-documentation/userGuide/dev_validator.html
    <field
        property="firstName" indexedListProperty="dependents"
        depends="requiredif">
      <arg0 key="dependentlistForm.firstName.label"/>
      <var>
        <var-name>field[0]</var-name>
        <var-value>lastName</var-value>
      </var>
      <var>
        <var-name>field-indexed[0]</var-name>
        <var-value>true</var-value>
      </var>
      <var>
        <var-name>field-test[0]</var-name>
        <var-value>NOTNULL</var-value>
      </var>
    </field>
    <field
        property="dob"
        indexedListProperty="dependents"
        depends="requiredif,date">
      <arg0 key="dependentlistForm.dob.label"/>
      <var>
        <var-name>field[0]</var-name>
        <var-value>lastName</var-value>
      </var>
      <var>
        <var-name>field-indexed[0]</var-name>
        <var-value>true</var-value>
      </var>
      <var>
        <var-name>field-test[0]</var-name>
        <var-value>NOTNULL</var-value>
      </var>
    </field>
    <field
        property="coverageType"
        indexedListProperty="dependents"
        depends="requiredif">
      <arg0 key="dependentlistForm.coverageType.label"/>
      <var>
        <var-name>field[0]</var-name>
        <var-value>lastName</var-value>
      </var>
      <var>
        <var-name>field-indexed[0]</var-name>
        <var-value>true</var-value>
      </var>
      <var>
        <var-name>field-test[0]</var-name>
        <var-value>NOTNULL</var-value>
      </var>
      <var>
        <var-name>field[1]</var-name>
        <var-value>insureDependents</var-value>
      </var>
      <var>
        <var-name>field-test[1]</var-name>
        <var-value>EQUAL</var-value>
      </var>
      <var>
        <var-name>field-value[1]</var-name>
        <var-value>true</var-value>
      </var>
      <var>
        <var-name>field-join</var-name>
        <var-value>AND</var-value>
      </var>
    </field>
    </form>" Which is read as follows: The firstName field is only required if the lastName field is non-null. Since field-indexed is true, it means that lastName must be a property of the same indexed field as firstName. Same thing for dob, except that we validate for date if not blank.
    The coverageType is only required if the lastName for the same indexed bean is not null, and also if the non-indexed field insureDependents is true.
    You can have an arbitrary number of fields by using the [n] syntax, the only restriction is that they must all be AND or OR, you can't mix. "
    Hope that helps,
    Nate

  • Apache commons fileUpload parseRequest finds no form fields-portalComponent

    Hello All,
    What am I trying?
    Developing a portal component (no JSP, no HTMLB).
    Have used Apache commons fileUpload libraries.
    What is the problem?
    parseRequest method works fine when I right click and preview from PCD.
    parseRequest method returns 0 html form elements when the portal component is tested under the TLN (via role -> workset -> iview)
    What else did I try?
    1.
    I looked in to Apache documentation - there are two different APIs for two different scenarios, Servlets and Portlets.
    My understanding is that I can not use portlets scenario in SAP Portal.
    Servlets scenario was what worked while doing a preview from PCD.
    2. I have looked into other solutions like using web dynpro and HTMLB to do file upload - not really a fan of either for various reasons.
    Can any one help?
    I am trying to understand why the HTTPServletRequest when parsed returns 0 form elements in the SAP Portal scenario.
    Thanks!

    Hello Ankur,
    You said:
    The reason for this is, unlike the request parameters, the multipart formdata is 'read-once-only' (because once
    the data is read off the ServletInputStream, it is gone! It cannot be read again). When you call a full portal request it goes through lot of gets before reaching your component.
    The above concept is not fully clear to me. I got a hint to something like this happening from this link that explains the need for portlets API scenario compared to a servlets scenario - Link: http://commons.apache.org/fileupload/using.html
    (Search for Servlets and Portlets within that link)
    I initially thought something like what you had replied would have happened. However, when I do a getContentLength on HTTPServletRequest in the SAP Portal mode (role -> workset -> iview), the size still includes that of the uploaded document. So like you said "it is gone! It cannot be read again" may not be accurate.
    My question still remains open.
    Edited by: Mohammed on Aug 24, 2009 6:29 PM

Maybe you are looking for