久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Apache Commons Net FTP 正在上傳損壞的文件

Apache Commons Net FTP is uploading corrupted files(Apache Commons Net FTP 正在上傳損壞的文件)
本文介紹了Apache Commons Net FTP 正在上傳損壞的文件的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試使用 Apache Commons Net 進(jìn)行 FTP 文件傳輸.

I'm trying to use Apache Commons Net for FTP file transfers.

問(wèn)題是文件間歇性地到達(dá)服務(wù)器損壞.損壞"是指 WinRAR 告訴我一個(gè) ZIP 文件有一個(gè) 意外結(jié)束存檔".有時(shí)文件完全是空的.我注意到大文件 (100kb+) 會(huì)發(fā)生這種情況,但小文件 (20kb) 也會(huì)發(fā)生這種情況.

Problem is files are intermittently arriving at the server corrupt. By 'corrupt' I mean that WinRAR tells me a ZIP file has an 'Unexpected end of archive'. Sometimes the files are completely empty. I have noticed that this happens more for larger files (100kb+), however does happen for small files too (20kb).

我知道上傳的源 zip 文件是有效的,并且只有 243kb.

I know for a fact that the source zip file being uploaded is valid, and is only 243kb.

我沒(méi)有從代碼中得到任何錯(cuò)誤/異常.

I do not get any errors/exceptions from the code.

這是正在執(zhí)行的代碼:

int CON_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(20); // fail if can't connect within 20 seconds
int LIVE_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(5); // allow up to 5 minutes for data transfers

FTPClient client = new FTPClient();
client.setConnectTimeout(CON_TIMEOUT);
client.setDataTimeout(LIVE_TIMEOUT);
client.connect(host);
client.setSoTimeout(LIVE_TIMEOUT);
client.login(user, pass);
client.changeWorkingDirectory(dir);
log("client ready");

File file = new File(filePath);
String name = new Date().getTime() + "-" + file.getName();

InputStream fis = null;
try
{
    fis = new FileInputStream(file);
    if (!client.storeFile(name, fis))
        throw new RuntimeException("store failed");
    log("store " + name + " complete");
}
finally
{
    IOUtils.closeQuietly(fis);
    try
    {
        client.logout();
        log("logout");
    }
    catch (Throwable e)
    {
        log("logout failed", e);
    }
    try
    {
        client.disconnect();
        log("disconnect");
    }
    catch (Throwable e)
    {
        log("disconnect failed", e);
    }
}

還有一些日志:

2010-08-10 21:32:38 client ready
2010-08-10 21:32:49 store 1281439958234-file.zip complete
2010-08-10 21:32:49 logout
2010-08-10 21:32:49 disconnect
2010-08-10 21:32:50 client ready
2010-08-10 21:33:00 store 1281439970968-file.zip complete
2010-08-10 21:33:00 logout
2010-08-10 21:33:00 disconnect
2010-08-10 21:33:02 client ready
2010-08-10 21:33:11 store 1281439982234-file.zip complete
2010-08-10 21:33:11 logout
2010-08-10 21:33:11 disconnect
2010-08-10 21:33:15 client ready
2010-08-10 21:33:25 store 1281439995890-file.zip complete
2010-08-10 21:33:26 logout
2010-08-10 21:33:26 disconnect
2010-08-10 21:33:27 client ready
2010-08-10 21:33:36 store 1281440007531-file.zip complete
2010-08-10 21:33:36 logout
2010-08-10 21:33:36 disconnect
2010-08-10 21:33:37 client ready
2010-08-10 21:33:48 store 1281440017843-file.zip complete
2010-08-10 21:33:48 logout
2010-08-10 21:33:48 disconnect
2010-08-10 21:33:49 client ready
2010-08-10 21:33:59 store 1281440029781-file.zip complete
2010-08-10 21:33:59 logout
2010-08-10 21:33:59 disconnect
2010-08-10 21:34:00 client ready
2010-08-10 21:34:09 store 1281440040812-file.zip complete
2010-08-10 21:34:09 logout
2010-08-10 21:34:09 disconnect
2010-08-10 21:34:10 client ready
2010-08-10 21:34:23 store 1281440050859-file.zip complete
2010-08-10 21:34:24 logout
2010-08-10 21:34:24 disconnect
2010-08-10 21:34:25 client ready
2010-08-10 21:34:35 store 1281440065421-file.zip complete
2010-08-10 21:34:35 logout
2010-08-10 21:34:35 disconnect

請(qǐng)注意,所有這些都在 15 秒內(nèi)完成,并且服務(wù)器上的所有生成文件都已損壞.

Note that all of these were complete within 15 seconds, and all of the resulting files on the server are corrupt.

我也進(jìn)行了測(cè)試,沒(méi)有設(shè)置任何超時(shí),問(wèn)題仍然存在.

I have also tested without setting any timeouts and the problem still occurs.

推薦答案

Common FTP 默認(rèn)為 Ascii 文件類型.在處理 ZIP 文件等二進(jìn)制數(shù)據(jù)時(shí),您希望將其設(shè)置為 Binary.

Commons FTP defaults to Ascii file types. You want to set it to Binary when dealing with binary data like a ZIP file.

來(lái)自 http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClient.html

FTPClient 的默認(rèn)設(shè)置是使用 FTP.ASCII_FILE_TYPE 、 FTP.NON_PRINT_TEXT_FORMAT 、 FTP.STREAM_TRANSFER_MODE 和 FTP.FILE_STRUCTURE .唯一直接支持的文件類型是 FTP.ASCII_FILE_TYPE 和 FTP.BINARY_FILE_TYPE .

The default settings for FTPClient are for it to use FTP.ASCII_FILE_TYPE , FTP.NON_PRINT_TEXT_FORMAT , FTP.STREAM_TRANSFER_MODE , and FTP.FILE_STRUCTURE . The only file types directly supported are FTP.ASCII_FILE_TYPE and FTP.BINARY_FILE_TYPE .

您想在發(fā)送文件之前執(zhí)行 setFileType(FTP.BINARY_FILE_TYPE).

You want to do setFileType(FTP.BINARY_FILE_TYPE) before you send the file.

這篇關(guān)于Apache Commons Net FTP 正在上傳損壞的文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 特a毛片| 秋霞在线一区 | 91精品国产色综合久久不卡蜜臀 | 91免费在线| 亚洲网站在线观看 | 亚洲一区二区三区免费在线观看 | 另类专区亚洲 | 久久成人精品视频 | 青青久在线视频 | 香蕉视频91 | 日韩久久精品 | 亚洲精品99| 爱高潮www亚洲精品 中文字幕免费视频 | 99re视频在线 | 91大神新作在线观看 | 久久成人综合 | a级在线| 日本成人一区二区 | 日韩精品国产精品 | 日本又色又爽又黄又高潮 | 国产精品美女久久久久久久网站 | 欧美精品在线免费观看 | 中文字幕一区二区三区在线视频 | 午夜爱爱网 | 操久久| 精品在线一区 | 国产美女h视频 | 福利视频一区二区三区 | 天天夜夜人人 | 午夜寂寞福利视频 | 国内自拍偷拍视频 | 91av免费看 | 国产精品精品视频 | 国产成人一区二区三区 | 九九热精品在线视频 | 日韩视频一区二区 | 大乳boobs巨大吃奶挤奶 | 亚洲精品亚洲人成人网 | 国产99久久精品一区二区永久免费 | 羞羞在线观看视频 | 欧美一级特黄aaa大片在线观看 |