Ftp File download From java code
turn off the firewall.in this issue
nomee.tec
Updated on June 04, 2022Comments
-
nomee.tec almost 2 years
i have this code to download a single file .
import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.apache.commons.net.ftp.FTPClient; public class NetTest { public static void main(String[] args){ FTPClient client = new FTPClient( ); OutputStream outStream; try {
this is the part of server and passwords .
client.connect( "servername" ); client.login("noman123", "pass"); String remoteFile = "/a.txt"; outStream = new FileOutputStream( "a.txt" );
simple fill downloading but error on this line
client.retrieveFile( remoteFile, outStream ); } catch(IOException ioe) { System.out.println( "Error communicating with FTP server." ); } finally { try { client.disconnect( ); } catch (IOException e) { System.out.println( "Problem disconnecting from FTP server" ); } } } }
and it gives me errors like i hope that u can understand the issue that i m facing now
java.net.SocketException: Software caused connection abort: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109) at java.net.SocketOutputStream.write(SocketOutputStream.java:153) at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221) at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291) at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295) at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141) at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229) at java.io.BufferedWriter.flush(BufferedWriter.java:254) at org.apache.commons.net.ftp.FTP.__send(FTP.java:496) at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:470) at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:547) at org.apache.commons.net.ftp.FTP.port(FTP.java:872) at org.apache.commons.net.ftp.FTPClient.openDataConnection(FTPClient.java:667) at org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1595) at FtpDownloadDemo.main(FtpDownloadDemo.java:25)
-
assylias almost 12 yearsInstead of printing a custom message, you should print the stack trace which would most likely give you useful information about what happened. (
ioe.printStackTrace()
) -
nomee.tec almost 12 yearsi already done this but it gives me un understandable texts
-
assylias almost 12 yearsthat un-understandable text could be very useful. Why don't you edit your question and add the content of that text at the bottom?
-
assylias almost 12 yearsYou have clicked on edit below your question, added your text and saved the edit?
-
assylias almost 12 yearsPossibly related: stackoverflow.com/questions/8607026/… which suggests a firewall issue.
-
-
nomee.tec almost 12 yearsi just done this and it says that i m connected and on the root but when i try to access some data it fails.