FTPClient에서 진행 상황을 업로드하십시오
-
12-12-2019 - |
문제
commons-net ftpclient를 사용하여 일부 파일을 업로드합니다.
업로드가 진행되는 방법 (지금 업로드 된 바이트 수)?
감사합니다
해결책
확실히 CopyStreamListener 아래에서는 파일 검색의 예제 (Commons-Io Wiki에서 복사)를 찾을 수 있으므로 다른 방법으로 쉽게 변경할 수 있습니다.
try {
InputStream stO =
new BufferedInputStream(
ftp.retrieveFileStream("foo.bar"),
ftp.getBufferSize());
OutputStream stD =
new FileOutputStream("bar.foo");
org.apache.commons.net.io.Util.copyStream(
stO,
stD,
ftp.getBufferSize(),
/* I'm using the UNKNOWN_STREAM_SIZE constant here, but you can use the size of file too */
org.apache.commons.net.io.CopyStreamEvent.UNKNOWN_STREAM_SIZE,
new org.apache.commons.net.io.CopyStreamAdapter() {
public void bytesTransferred(long totalBytesTransferred,
int bytesTransferred,
long streamSize) {
// Your progress Control code here
}
});
ftp.completePendingCommand();
} catch (Exception e) { ... }
. 다른 팁
나는이 목적을 위해 의도 된 것처럼 보이기 때문에 카운트 링 슈트 스트림을 우리에게 더 낫다고 생각한다.
이것은 여기에 누군가에 의해 답변됩니다 : Apache Commons ftpclient를 사용하여 진행 상황 ftpclient
제휴하지 않습니다 StackOverflow