Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

File is null when downloaded from unix

Thread view: 
Guan - 07 Nov 2006 14:16 GMT
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 - 07 Nov 2006 14:59 GMT
> 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 - 08 Nov 2006 16:02 GMT
y need this line "System.getProperty("path.separator") ?"
> > Hi All,
> >
[quoted text clipped - 9 lines]
>
> Andrew T.
Andrew Thompson - 08 Nov 2006 16:45 GMT
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 Nov 2006 12:59 GMT
Hi All,

Thanks for your help.  I had solve the problem :)
Guan - 11 Nov 2006 12:59 GMT
Hi All,

Thanks for your help.  I had solve the problem :)
Guan - 11 Nov 2006 13:00 GMT
Hi All,

Thanks for your help.  I had solve the problem :)
Guan - 11 Nov 2006 13:01 GMT
Hi All,

Thanks for your help. My problem is solved. :)
Luc The Perverse - 11 Nov 2006 19:48 GMT
> 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

:)
Thomas Hawtin - 07 Nov 2006 15:49 GMT
> 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 - 08 Nov 2006 16:11 GMT
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

> > 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
[quoted text clipped - 17 lines]
>
> Tom Hawtin


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.