Results 1 to 10 of 10

Thread: ftp proplem

  1. #1
    munish is offline Member
    Join Date
    Jul 2009
    Posts
    37
    Rep Power
    0

    Default ftp proplem

    hi i am tring to append string to file already existing file in ftp so i am using folllowing code but some how output is

    out is null
    d
    null pointer execption

    Java Code:
                String s="data";
                fis=new ByteArrayInputStream(s.getBytes());
                FTPClient ftp = new FTPClient();
                ftp.connect(Url);
                ftp.login(user,pass);
                ftp.changeWorkingDirectory(Folder);
                
                out = ftp.appendFileStream(file);
    
                if(out == null){
                    System.out.println("out is null");
                }
                while(fis.available() != 0){
                    System.out.println((char)fis.read());
                    out.write((char)fis.read());
                }
    Last edited by munish; 11-02-2010 at 12:18 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    After changin the working directory do a listFiles and print out all the files.
    Also print out the name of "file".
    Check that "file" exists in the list of files.

  3. #3
    munish is offline Member
    Join Date
    Jul 2009
    Posts
    37
    Rep Power
    0

    Default

    thanks for rply..

    yes the file exist in ftp.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    No, have you changed your code to print out the result of listFiles() on the ftp cionnection.

    Have you changed your code to print out the value of "file"?

    If so, can you show us the code and the results?

  5. #5
    munish is offline Member
    Join Date
    Jul 2009
    Posts
    37
    Rep Power
    0

    Default

    error:org/apache/oro/text/regex/MalformedPatternException

    Java Code:
    String s="data";
                fis=new ByteArrayInputStream(s.getBytes());
                FTPClient ftp = new FTPClient();
                ftp.connect(Url);
                ftp.login(user,pass);
                ftp.changeWorkingDirectory(Folder);
                
    
                FTPFile[] ftpFiles = ftpClient.listFiles();
    
                for (int i = 0; i < ftpFiles.length; i++)
                {
                    String file = ftpFiles[i].getName();
                    System.out.println(file);
                }
    Last edited by munish; 11-02-2010 at 02:50 PM.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

    Default

    And where is that thrown from?
    What line?
    Full stack trace?

    Was anything printed out?

    Come on, put some effort into your own problem!

  7. #7
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by munish View Post
    hi i am tring to append string to file already existing file in ftp so i am using folllowing code but some how output is

    out is null
    d
    null pointer execption

    the FTPClient API suggest

    Immediately after connecting is the only real time you need to check the reply code (because connect is of type void). The convention for all the FTP command methods in FTPClient is such that they either return a boolean value or some other value. The boolean methods return true on a successful completion reply from the FTP server and false on a reply resulting in an error condition or failure. The methods returning a value other than boolean return a value containing the higher level data produced by the FTP command, or null if a reply resulted in an error condition or failure. If you want to access the exact FTP reply code causing a success or failure, you must call getReplyCode after a success or failure.

    look at the example code in the link, insert the statements in your code to get the reply code and post it.

  8. #8
    munish is offline Member
    Join Date
    Jul 2009
    Posts
    37
    Rep Power
    0

    Default

    thanks for all ur reply..

    solution to this problem is ...ftpClient.enterLocalPassiveMode().

  9. #9
    sunjay is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default

    in these many of the ftp problem is mostly relative to the entire response of the problem occurs.
    __________________________________________________ ______
    Budget Hotels In kanyakumari | Kanyakumari Budget Accommodation | Kanyakumari Tourism

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,178
    Rep Power
    20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •