Results 1 to 5 of 5
  1. #1
    AnishThomas is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default FTP corrupts images

    Hi,

    I am using sun.net.ftp.FTPClient. I am using the same code in two servers.

    The code in the first server works perfectly fine.

    The code in the second server uploads the files, but corrupts the image files. I suspect that it is uploaded in ascii mode. But, I am not able to figure out the reason. My code explicitly sets the mode to binay
    Java Code:
    client.binary();
    Can anyone please help?

    My code is simlar to the one below:

    Java Code:
    import java.io.*;
    import sun.net.ftp.FtpClient;
    
    public class FtpExample {
    
      public static void main(String args[]) throws Exception {
    
        FtpClient fc;
    
        String host = args[0];
        String path = args[1];
        String username = args[2];
        String password = args[3];
    
        int lastSlash = path.lastIndexOf('/');
        String filename = path.substring(lastSlash+1);
        String directory = path.substring(0,lastSlash);
    
        FtpClient client = new FtpClient(host);
        client.login(username, password);
        client.binary();
        client.cd(directory);
    
        InputStream is = client.get(filename);
        BufferedInputStream bis = new BufferedInputStream(is);
    
        OutputStream os = new FileOutputStream(filename);
        BufferedOutputStream bos = new BufferedOutputStream(os);
    
        byte[] buffer = new byte[1024];
        int readCount;
    
        System.out.println("Getting: " + filename);
                        
        while( (readCount = bis.read(buffer)) > 0) {
          bos.write(buffer, 0, readCount);
        }
        bos.close();
    //    client.closeServer();
      }
    }

  2. #2
    AnishThomas is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: FTP corrupts images

    Anyone has any ideas? I am using websphere, Unix, Java 5

  3. #3
    AnishThomas is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: FTP corrupts images

    Any help is appreciated. Please tell me if more details are required.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default Re: FTP corrupts images

    I don't have the API doc for that class. Are you sure the binary() method does what you want?
    Normally a method that sets a value would have a name starting with set....

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: FTP corrupts images

    Quote Originally Posted by AnishThomas View Post
    Hi,

    I am using sun.net.ftp.FTPClient.
    Possibly your mistake.
    The sun* stuff is not supposed to be used directly, as far as I'm aware.

    Try something like Apache's FTPClient (I think it's part of the commons library).

Similar Threads

  1. Replies: 0
    Last Post: 12-16-2010, 05:14 PM
  2. Replies: 4
    Last Post: 12-16-2010, 04:32 PM
  3. Images
    By Witik in forum New To Java
    Replies: 7
    Last Post: 09-13-2010, 01:34 PM
  4. images
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-20-2008, 10:54 AM
  5. Images in JSP
    By Daniel in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-05-2007, 06:01 AM

Tags for this Thread

Posting Permissions

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