File is null when downloaded from unix

G

Guan

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
 
A

Andrew Thompson

Guan said:
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.
 
T

Thomas Hawtin

Guan said:
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
 
G

Guan

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
 
A

Andrew Thompson

Guan wrote:

Please refrain from top-posting.

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..

...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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top