FTP上传报Broken pipe错误,原因解析

 具体报错如下:

2020-06-02 15:03:33.187 16271-16626/com.xxx.xxx W/System.err: java.net.SocketException: Broken pipe
2020-06-02 15:03:33.189 16271-16626/com.xxx.xxx W/System.err:     at java.net.SocketOutputStream.socketWrite0(Native Method)
2020-06-02 15:03:33.189 16271-16626/com.xxx.xxx W/System.err:     at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
2020-06-02 15:03:33.189 16271-16626/com.xxx.xxx W/System.err:     at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
2020-06-02 15:03:33.189 16271-16626/com.xxx.xxx W/System.err:     at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
2020-06-02 15:03:33.190 16271-16626/com.xxx.xxx W/System.err:     at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
2020-06-02 15:03:33.190 16271-16626/com.xxx.xxx W/System.err:     at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
2020-06-02 15:03:33.190 16271-16626/com.xxx.xxx W/System.err:     at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
2020-06-02 15:03:33.190 16271-16626/com.xxx.xxx W/System.err:     at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
2020-06-02 15:03:33.190 16271-16626/com.xxx.xxx W/System.err:     at it.sauronsoftware.ftp4j.NVTASCIIWriter.writeLine(NVTASCIIWriter.java:133)
2020-06-02 15:03:33.190 16271-16626/com.xxx.xxx W/System.err:     at it.sauronsoftware.ftp4j.FTPCommunicationChannel.sendFTPCommand(FTPCommunicationChannel.java:165)
2020-06-02 15:03:33.190 16271-16626/com.xxx.xxx W/System.err:     at it.sauronsoftware.ftp4j.FTPClient.createDirectory(FTPClient.java:1930)
2020-06-02 15:03:33.191 16271-16626/com.xxx.xxx W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:333)
2020-06-02 15:03:33.191 16271-16626/com.xxx.xxx W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2020-06-02 15:03:33.191 16271-16626/com.xxx.xxx W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
2020-06-02 15:03:33.191 16271-16626/com.xxx.xxx W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2020-06-02 15:03:33.192 16271-16626/com.xxx.xxx W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2020-06-02 15:03:33.192 16271-16626/com.xxx.xxx W/System.err:     at java.lang.Thread.run(Thread.java:764)

经过代码走差,发现ftp在第一次使用完之后未关闭和清空导致,添加如下代码即可

try {
            ftp.closeConnect();
            ftp = null;
        } catch (IOException e) {
            e.printStackTrace();
        }

 

你可能感兴趣的:(安卓)