1

I want to download a file in java application and when I try it, it creates the file on my hard drive but then fails to download it completely. I am using the ftp4j library to do it.

import it.sauronsoftware.ftp4j.*;
public class Main {
public static void main (String args[]){
    FTPClient client = new FTPClient();
    try{
    client.connect("ftp.myaddress.comlu.com");
    client.login("username", "password");
    System.out.println("Connection created");
    client.download("public_html/ZScreen.png", new java.io.File("d:/xxx/ZScreen.png"));
    System.out.println("Download successful");
    client.disconnect(true);
    }
    catch (Exception FTPException){
    System.out.println("Shit hit the fan");
    }
}
}

I always get the Connection created and Shit hit the fan. Also, there is a file created on my hard drive but it's size is 0 bytes.

This is the stack race

Connection created
java.net.SocketException: Connection reset
Shit hit the fan
at java.net.SocketInputStream.read(SocketInputStream.java:189)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:126)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:112)
at java.io.InputStreamReader.read(InputStreamReader.java:168)
at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:105)
at     it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunicationChannel.java:142)
at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommunicationChannel.java:187)
at it.sauronsoftware.ftp4j.FTPClient.openPassiveDataTransferChannel(FTPClient.java:3538)
at it.sauronsoftware.ftp4j.FTPClient.openDataTransferChannel(FTPClient.java:3473)
at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3302)
at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3213)
at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3078)
at Main.main(Main.java:9)
3
  • There is no stack trace. I might have inserted a wrong Exception type Apr 15, 2012 at 23:22
  • Try catch (Exception e) { e.printStackTrace(); } instead of the catch block you have now...
    – Torious
    Apr 15, 2012 at 23:24
  • thank you, I will edit my post with stack trace Apr 16, 2012 at 9:40

2 Answers 2

5

Apparently there is a bug on the Windows 7 firewall related to using FTP on IPv6 that would explain your problem. See bug report here.

Any one of the following workarounds should suffice to fix it:

  • Run the following as an administrator in a Windows console:

    netsh advfirewall set global StatefulFtp disable

  • Run the JVM with the option: -Djava.net.preferIPv4Stack=true

0
1

You do not have the rights to write on the folder. Check if the repertory is not under "read-only" state.

1
  • upvoting as I was having a similar problem and this was the clue I needed. Thank you
    – nathj07
    Nov 11, 2014 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.