Not able to download a large file in java ftp - java

I am working on a project in JavaFX. I need to download a file from the server for that I am using the ftp connection and downloading the file.
The size of the file is 560 MB, while downloading the file the code doesn't give any error but when I check the size of the file in the download location it is only 485 MB and I am not able to open it.
My code for downloading is:
OutputStream output = new FileOutputStream(toPath + "/" + dfile);
if(ftpClient.retrieveFile(dfile, output))
{
downloadButton.setDisable(true);
}
output.close();
Does java ftp have some download file size limit? How to resolve this problem? I have heard of chunking but don't know how to implement it in this case.

I downloaded the files in binary mode and it's working fine now.
ftpClient.setFileType(FTP.BINARY_FILE_TYPE)

Related

How to unzip file zipped by PKZIP in mainframe by Java?

I am trying to write a program in Java to unzip files zipped by PKZIP tool in Mainframe. However, I have tried below 3 ways, none of them can solve my problem.
By exe.
I have tried to open it by WinRAR, 7Zip and Linux command(unzip).
All are failed with below error message :
The archive is either in unknown format or damaged
By JDK API - java.util.ZipFile
I also have tried to unzip it by JDK API, as this website described.
However, it fails with error message :
IO Error: java.util.zip.ZipException: error in opening zip file
By Zip4J
I also have tried to use Zip4J. It failed too, with error message :
Caused by: java.io.IOException: Negative seek offset
at java.io.RandomAccessFile.seek(Native Method)
at net.lingala.zip4j.core.HeaderReader.readEndOfCentralDirectoryRecord(HeaderReader.java:117)
... 5 more
May I ask if there is any java lib or linux command can extract zip file zipped by PKZIP in Mainframe? Thanks a lot!
I have successfully read files that were compressed with PKZip on z/OS and transferred to Linux. I was able to read them with java.util.zip* classes:
ZipFile ifile = new ZipFile(inFileName);
// faster to loop through entries than open the zip file as a stream
Enumeration<? extends ZipEntry> entries = ifile.entries();
while ( entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) { // skip directories
String entryName = entry.getName();
// code to determine to process omitted
InputStream zis = ifile.getInputStream(entry);
// process the stream
}
}
The jar file format is just a zip file, so the "jar" command can also read such files.
Like the others, I suspect that maybe the file was not transferred in binary and so was corrupted. On Linux you can use the xxd utility (piped through head) to dump the first few bytes to see if it looks like a zip file:
# xxd myfile.zip | head
0000000: 504b 0304 2d00 0000 0800 2c66 a348 eb5e PK..-.....,f.H.^
The first 4 bytes should be as shown. See also the Wikipedia entry for zip files
Even if the first 4 bytes are correct, if the file was truncated during transmission that could also cause the corrupt file message.

Java POI - can't access xls file on Win 2003 Server

i have a small app. it takes xls file and transforms it into xml. everything works fine on my two local machines win xp 32 (java 7) and win 7 64 (java 8) but when i started app on win 2003 server things went a bit strange.
on win server it gives me error:
org.apache.poi.EmptyFileException: The supplied file was empty (zero bytes long)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:218)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:168)
at Parser.xlsToXml(Parser.java:43)
at Parser.<init>(Parser.java:28)
as you can see i use java poi lib to parse xls.
this is part of code where error occures:
Biff8EncryptionKey.setCurrentUserPassword(params.get("pass"));
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(params.get("xls_location")), true);//string 43!!!
before i try to access this xls file i'm successfully getting params for app to work from text file located in the same folder on server as xls file is with this code:
encoded = Files.readAllBytes(Paths.get(dir+fileName));
return new String(encoded,getFileCharset(dir+fileName));
so i mean that i have all rights for reading and writing in the directory.
i tried to google this but found nothing that could help. i'm really stuck here. folder on the server has same right as folders on my win xp and win 7 home computers. also i allways use the same xls file on all machines.
so what do i do wrong?..
any help appriciated!

incompletely download of pgp file from ftp sever using apache.commons.net

I'm trying to transfer a pgp file with apache.commons.net.ftp.FTPClient, result seems successfully, but when I want to convert it to a txt file I encounter to this error:
gpg: [don't know]: invalid packet (ctb=20)
and when I check the exact size of downloaded file, I notice that it's size is about 1KB less than original file.
here is the code for downloading file:
FileOutputStream fos = new FileOutputStream(Localfilename);
InputStream inputStream = ftpClient.retrieveFileStream(remoteFileDir);
IOUtils.copy(inputStream, fos);
fos.flush();
IOUtils.closeQuietly(fos);
IOUtils.closeQuietly(inputStream);
boolean commandOK = ftpClient.completePendingCommand();
can any one understand what is mistake with my way or code?
[edited] noted that the original file decode (convert to txt)successfully, so the problem occures while downloading file.
[edited2] I run the program in my windows desktop and download file in windows, no problem for decode, and I understand that when I run my program with linux server this problem appears!
I found my problem!
The problem was with addressing the remote path, a silly mistake!
so If any one has this problem recheck and recheck again the addresses.

com.sun.star.lang.IllegalArgumentException - Unsupported URL <file:///

Hi Stackoverflow community, i am having an issue about reading a file from my java webapp. I want to get a file from a directory in my webapp, then converting it to PDF. Everything works just fine in my developpement environement ( Windows) but when i am puting this on sever ( LINUX), when the server reach the code to read my doc file to convert it, java throw this exception :
com.sun.star.lang.IllegalArgumentException - Unsupported URL <file:///
Here is the code :
fileDocToConvert = new File(GET_REAL_PATH()+repo_Name+slash+fileName);
fileDocToConvert path become then : /usr/share/tomcat7/webapps/myapp/repo_name/exemple.doc
the exception fired up when i try to convert :
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
//HERE...=> // converter.convert(docFile, pdfFile);
I am using :
jodConverter 2.2.1, openOffice 3, Java7, Tomcat 7
I start the openOffice service this way :
soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard
I can't get a way to follow to solve this issue.
Thank you in advance
I resolved the problem, by installing some missing components of OpenOffice ( Calc, Writer ). The problem was that OpenOffice can't understand the path of the file given to it.
Thank's for your help millimoose.
Have got java.lang.Exception: Unsupported URL <file:////... error message when started multiple libreoffice instances from different users and with conflicting same port setting.
The problem for me was that OpenOffice or another program that uses components of OpenOffice in it cannot understand the path of the file given to it as a place to save the file. Save the file that you are trying to save somewhere else on your computer and see if that works.

java.io.IOException: Permission denied on network folder

i'm having the the post's title error when trying to write a file on a window folder , mounted on unix system. I've developed a web service which runs inside a Tomcat 6 on a linux os and need to write on a windows network folder. System administrators have mounted it on the Linux sever and have no problem to create and modify a file on it.
When i try to execute the posted code i get the following exception :
Permission denied
java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:850)
The weird thing is that it seems to be related to the File.createNewFile method on a network folder , in fact the service can write on local file system without problems, both on debug (the pc i use to develop the service) and a tomcat folder system administrators have provided me on the linux server. The file gets created but is empty and the log entry following the create method doesn't get printed. Moreover if i use a plain outputstream to create and write the file i've no problems.
I cannot find any explanation about the exception on the web. Since i'm not very experienced with java , i'd like to understand why i'm getting this error. Am i using it in the wrong way ? Is it a bug of the library ? Do i miss to pass some parameter ?
As stated , i've solved the problem using a plain outputstream, this is a question to improve my understanding of java.
FileOutputStream fos = null;
try{
log.info(String.format("file length: %s",streamAttach.length));
log.info(String.format("check File : %s",filename));
File f = new File(filename);
if(f.exists())
...
boolean done= f.createNewFile();//here comes the exception
//nothing of the following happens
if(!done)
throw new NWSException("error creating file");
log.info(String.format("file %s creato", nomeFile));
thank you in advance for any answer
I ran into this problem recently and found that java.io.File.createNewFile() actually requires the "Change Permissions" permission (you can find this entry under Security->Advanced when checking folder permissions). Without this it will create the file and then subsequently throw an IOException.
It's deceptive because you will still be able to create files on the folder when manually testing, however createNewFile() will still fail if it doesn't have this particular permission (presumably such that it can change the permissions on the file its creating).
If you are using Netapp that shares an NTFS (CIFS) style filesystem to Unix you could be experience "NFS is not allowed to change permissions on a file in an NTFS-style security volume." (TR-3490 page 16)
Options here are to change to a unix filesystem or set the cifs.ntfs_ignore_unix_security_ops flag to on for the file system which quiches the NFS permission error.
java.io.UnixFileSystem.createFileExclusively(Native Method) opens the file with the O_EXCL and 0666 umask so I would get a EACCES, which really was a NFS3RR_ACCES
open("/net/storage01-a/filer/myfile", O_RDWR|O_CREAT|O_EXCL, 0666) Err#13 EACCES
Also you can use OutputStream to create the file, that does not use O_EXCL it seemes
It definitely not Java specific problem. If this Unix folder is mapped to your windows try to open file explorer and create file in this directory. I believe that you will get permission denied too. In this case fix this problem or ask your system administrator to help you.
Good luck!

Categories

Resources