File is null when downloaded from unix

Discussion in 'Java' started by Guan, Nov 7, 2006.

  1. Guan

    Guan Guest

    Hi All,

    Following ocde is used to download file from unix server, when i try on
    window server, the downloading is fine. However when i download from
    unix server in binary mode. The file is empty. Is there anything i
    should take note of when trying to download file from unix

    ==============================================================

    // Retrieve the file
    response.setHeader("Content-Type",
    "application/x-download");
    response.setHeader("Content-Disposition","attachment;
    filename=\"" + fileName);

    outputStream = response.getOutputStream();

    //outputLocalBuf = new
    BufferedOutputStream(outputLocal);


    ....................................................................

    ........................................................................

    inputStream = new BufferedInputStream((fileName));

    int data;

    while((data = inputStream.read()) != -1) {
    outputStream.write(data);
    }
    }


    thanks
    Guan, Nov 7, 2006
    #1
    1. Advertising

  2. Guan wrote:
    > Hi All,
    >
    > Following ocde is used to download file from unix server, when i try on
    > window server, the downloading is fine. However when i download from
    > unix server in binary mode. The file is empty. Is there anything i
    > should take note of when trying to download file from unix

    ....
    > response.setHeader("Content-Disposition","attachment;
    > filename=\"" + fileName);


    System.getProperty("path.separator") ?

    Andrew T.
    Andrew Thompson, Nov 7, 2006
    #2
    1. Advertising

  3. Guan wrote:
    >
    > Following ocde is used to download file from unix server, when i try on
    > window server, the downloading is fine. However when i download from
    > unix server in binary mode. The file is empty. Is there anything i
    > should take note of when trying to download file from unix


    What do you mean binary mode? Non text/ content type?

    > response.setHeader("Content-Disposition","attachment;
    > filename=\"" + fileName);


    My knee-jerk reaction is that if you don't know for sure the source of
    fileName, could have something malicious in it (new lines, NUL
    characters, double quotes, that sort of stuff). My second reaction is
    that you only have a single double quote.

    > inputStream = new BufferedInputStream((fileName));


    I take it this isn't your real code. It's difficult to diagnose problems
    without seeing the actual code.

    Tom Hawtin
    Thomas Hawtin, Nov 7, 2006
    #3
  4. Guan

    Guan Guest

    y need this line "System.getProperty("path.separator") ?"
    Andrew Thompson wrote:
    > Guan wrote:
    > > Hi All,
    > >
    > > Following ocde is used to download file from unix server, when i try on
    > > window server, the downloading is fine. However when i download from
    > > unix server in binary mode. The file is empty. Is there anything i
    > > should take note of when trying to download file from unix

    > ...
    > > response.setHeader("Content-Disposition","attachment;
    > > filename=\"" + fileName);

    >
    > System.getProperty("path.separator") ?
    >
    > Andrew T.
    Guan, Nov 8, 2006
    #4
  5. Guan

    Guan Guest

    Hi,

    Thanks for all of you for your time for reading my posting and giving
    comments

    I hope the following code is sufficient for you. THis the not the full
    program it is the downloading part as the whole program is quite long

    I am using netcomponents FTP class to retrive file from FTP server, I
    tested this code to retrive file From FTP running on windows platform
    and it seem ok.. Howerver when i tried to retrieve file from ftp server
    on unix plaform. The file i download is empty content

    ==========================================================
    ftp = new FTPClient();
    ftp.connect(FTP_SERVER);
    int reply = ftp.getReplyCode();
    if
    (!com.oroinc.net.ftp.FTPReply.isPositiveCompletion(reply))
    throw new java.io.IOException("Could not connect to ftp
    server " +
    FTP_SERVER);
    ftp.login(ftpUserId, ftpPassword);
    ftp.setFileType(com.oroinc.net.ftp.FTP.BINARY_FILE_TYPE);
    ftp.changeWorkingDirectory(ftp.printWorkingDirectory());
    try {

    // Retrieve the file
    response.setHeader("Content-Type",
    "application/x-download");
    response.setHeader("Content-Disposition","attachment;
    filename=\"" + fileName);

    outputStream = response.getOutputStream();

    //outputLocalBuf = new
    BufferedOutputStream(outputLocal);
    if (ftp.retrieveFileStream(fileName)==null)
    throw new java.io.IOException(
    "Get file from remote ftp host failed");
    else{

    inputStream = new BufferedInputStream(
    (ftp.retrieveFileStream(fileName)));

    int data;

    while((data = inputStream.read()) != -1) {
    outputStream.write(data);
    }
    }
    } finally {
    if (inputStream != null) inputStream.close();
    if (outputStream != null) outputStream.close();



    Thanks


    Thomas Hawtin wrote:
    > Guan wrote:
    > >
    > > Following ocde is used to download file from unix server, when i try on
    > > window server, the downloading is fine. However when i download from
    > > unix server in binary mode. The file is empty. Is there anything i
    > > should take note of when trying to download file from unix

    >
    > What do you mean binary mode? Non text/ content type?
    >
    > > response.setHeader("Content-Disposition","attachment;
    > > filename=\"" + fileName);

    >
    > My knee-jerk reaction is that if you don't know for sure the source of
    > fileName, could have something malicious in it (new lines, NUL
    > characters, double quotes, that sort of stuff). My second reaction is
    > that you only have a single double quote.
    >
    > > inputStream = new BufferedInputStream((fileName));

    >
    > I take it this isn't your real code. It's difficult to diagnose problems
    > without seeing the actual code.
    >
    > Tom Hawtin
    Guan, Nov 8, 2006
    #5
  6. Guan wrote:

    Please refrain from top-posting.

    > y...


    Is something wrong with the 'w' and 'h' keys
    on your keyboard? Please fix it.

    >...need this line "System.getProperty("path.separator") ?"


    OK, given I am not psychic, I will take you back to this line..

    > > > response.setHeader("Content-Disposition","attachment;
    > > > filename=\"" + fileName);


    ...and ask.

    1) What is the content of the String referenced by fileName
    at this point in the code?
    2) What did your perusal of the JavaDocs, and the output
    of the path.separator string, suggest it means to you?

    Andrew T.
    Andrew Thompson, Nov 8, 2006
    #6
  7. Guan

    Guan Guest

    Hi All,

    Thanks for your help. I had solve the problem :)
    Guan, Nov 11, 2006
    #7
  8. Guan

    Guan Guest

    Hi All,

    Thanks for your help. I had solve the problem :)
    Guan, Nov 11, 2006
    #8
  9. Guan

    Guan Guest

    Hi All,

    Thanks for your help. I had solve the problem :)
    Guan, Nov 11, 2006
    #9
  10. Guan

    Guan Guest

    Hi All,

    Thanks for your help. My problem is solved. :)
    Guan, Nov 11, 2006
    #10
  11. "Guan" <> wrote in message
    news:...
    > Hi All,
    >
    > Thanks for your help. My problem is solved. :)


    Now to address the issue of you posting your reply 4 times without quoting

    --
    LTP

    :)
    Luc The Perverse, Nov 11, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Cooke
    Replies:
    2
    Views:
    1,543
    MS News \(MS ILM\)
    Aug 15, 2003
  2. ntm

    downloaded file is missing

    ntm, Jan 21, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    352
  3. ProJee
    Replies:
    0
    Views:
    795
    ProJee
    Jul 21, 2004
  4. Replies:
    5
    Views:
    26,476
    Mike Schilling
    Mar 29, 2006
  5. Brett  Kelly
    Replies:
    1
    Views:
    662
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
Loading...

Share This Page