Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   File is null when downloaded from unix (http://www.velocityreviews.com/forums/t388404-file-is-null-when-downloaded-from-unix.html)

Guan 11-07-2006 02:16 PM

File is null when downloaded from unix
 
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


Andrew Thompson 11-07-2006 02:59 PM

Re: File is null when downloaded from unix
 
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.


Thomas Hawtin 11-07-2006 03:49 PM

Re: File is null when downloaded from unix
 
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 11-08-2006 04:02 PM

Re: File is null when downloaded from unix
 
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 11-08-2006 04:11 PM

Re: File is null when downloaded from unix
 
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.printWorkingDirecto ry());
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



Andrew Thompson 11-08-2006 04:45 PM

Re: File is null when downloaded from unix
 
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.


Guan 11-11-2006 12:59 PM

Re: File is null when downloaded from unix
 
Hi All,

Thanks for your help. I had solve the problem :)


Guan 11-11-2006 12:59 PM

Re: File is null when downloaded from unix
 
Hi All,

Thanks for your help. I had solve the problem :)


Guan 11-11-2006 01:00 PM

Re: File is null when downloaded from unix
 
Hi All,

Thanks for your help. I had solve the problem :)


Guan 11-11-2006 01:01 PM

Re: File is null when downloaded from unix
 
Hi All,

Thanks for your help. My problem is solved. :)



All times are GMT. The time now is 12:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.