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

.



Relevant Pages

  • RE: FTP downloads to server timeout after 60 seconds
    ... Please download a big file via IE browser from Internet, ... Please make a clean boot on SBS server to make sure the problem is ... Click Services tab and select Hide All Microsoft Services and Disable ... Send the .cab file directly to v-robeli@xxxxxxxxxxxxx with subject: FTP ...
    (microsoft.public.windows.server.sbs)
  • Re: FTP download failure - fails at exactly the same point in the transfer file.
    ... command line ftp utility. ... backup file it failed at about 48Mb. ... download got stuck mid-way. ... server is broke too. ...
    (microsoft.public.windows.server.general)
  • Re: FTP difficulties 4.8R
    ... > with email, http, it runs an ftp server and client fine (both are ... I downloaded my FreeBSD ISOs without difficulty... ... > It does go outside and connect, sometimes I can ftp download some small ... > install Samba to better network with the Windows machine - I cannot download ...
    (freebsd-questions)
  • Re: Saving image from web without using adodb.stream
    ... It's easy to install an FTP program if you ... code and string the server gave to your request. ... You can download the source code for a VB6 ... VB6 with no dependencies other than the VB6 runtime. ...
    (microsoft.public.scripting.vbscript)
  • Re: BizTalk 2006: FTP Adapter Stops Polling
    ... When this happens to me it's because the file can't be parsed and isn't deleted from the server by the adapter. ... write and delete permissions on your Unix server. ... you are getting does not parse correctly, the FTP adapter will not ...
    (microsoft.public.biztalk.general)