2

FTPClient を使用してローカル ファイルをアップロードしていますが、修正方法がわからないバグがあります。

コードは次のとおりです。

public UploadStatus uploadFile(String remoteFile,File localFile,FTPClient ftpClient,long remoteSize) throws IOException{  
        UploadStatus status;
        long step = localFile.length() / 100;  
        long process = 0;  
        long localreadbytes = 0L;  
        RandomAccessFile raf = new RandomAccessFile(localFile,"r");

        //Here is the point, some times, it's frozen here, no reponse from the server.
        OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("UTF-8"),"iso-8859-1"));  

        //breakpoint resume  
        if(remoteSize>0){  
            ftpClient.setRestartOffset(remoteSize);  
            process = remoteSize /step;  
            raf.seek(remoteSize);  
            localreadbytes = remoteSize;  
        }  
        byte[] bytes = new byte[1024];  
        int c;  
        while((c = raf.read(bytes))!= -1){  
            out.write(bytes,0,c);  
            localreadbytes+=c;  
            if(localreadbytes / step != process){  
                process = localreadbytes / step;  
                System.out.println("progress:" + process);  
                //TODO call the progressbar function here 
            }  
        }  
        out.flush();  
        raf.close();  
        out.close();  
        boolean result =ftpClient.completePendingCommand();
}

次の行については、

OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("UTF-8"),"iso-8859-1"));

うまくいくこともあれば、うまくいかないこともあります。サーバーに存在しない新しいファイルをアップロードすると、おそらくうまく機能し、100% になりますが、ファイルの一部をアップロードしてから凍結することもあります。(例: 45%)、 [ ] 応答がない
ため、コードをデバッグして見つけました。ftpClient.appendFileStream

ありがとう 。

4

0 に答える 0