Java FTP上传创建一个空文件

Java FTP upload creates an empty file(Java FTP上传创建一个空文件)
本文介绍了Java FTP上传创建一个空文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当我尝试使用 Apache Commons FTPClient 上传一个简单的文本文件时:

When I try to upload a simple text file with the Apache Commons FTPClient and this code:

FTPClient ftp = new FTPClient();
int reply;

// connect
try {

    ftp.connect(serverAdd);
    ftp.login(username,password);
    reply = ftp.getReplyCode();

    if(FTPReply.isPositiveCompletion(reply)){
        System.out.println("Connected Success..");

        // upload file
        try {
            String fileDir = "testfile.txt";
            FileInputStream in = null;         
            in = new FileInputStream(fileDir);       
            ftp.storeFile(fileDir,in);
            System.out.println("File upload complete..");
        }catch(IOException e){
            System.out.println(e);
        }

        ftp.disconnect();
        System.out.println("Disconnected..");

    }else {
        System.out.println("Connection Failed..");
        ftp.disconnect();
    }    

} catch (SocketException ex) {
    ex.printStackTrace();
} catch (IOException ex) {
    ex.printStackTrace();
}

在 FTP 服务器的根目录中创建了一个文件,但它是空的.怎么了?上传 PDF 文件时,我已经尝试将 ftp 模式更改为 BINARY.但文件大小也是 0.

A file gets created in the root of the FTP server but it is empty. What's wrong? I already tried to change the ftp mode to BINARY when uploading a PDF file. But the file is also 0 in size.

ftp.setFileType(FTP.BINARY_FILE_TYPE);

我也只想上传一堆txt文件,所以默认ascii模式应该没问题吧?

I also only want to upload a bunch of txt files, so the default ascii mode should be fine, right?

推荐答案

好吧,看来是我的防火墙问题了.当我停用防火墙时,文件会毫无问题地写入 ftp.

ok, it seems that it is a probem with my firewall. when I deactivate the firewall the file gets written to the ftp with no problem.

这篇关于Java FTP上传创建一个空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android sdk 18 TextView gravity doesn#39;t work vertically(Android sdk 18 TextView 重力不能垂直工作)
Java android: appending a newline using TextView(Java android:使用 TextView 添加换行符)
How to create simple Android TextView and display text on it using java code?(如何使用 java 代码创建简单的 Android TextView 并在其上显示文本?)
Add opaque quot;shadowquot; (outline) to Android TextView(添加不透明的“阴影(大纲)到 Android TextView)
Android: Creating a Circular TextView?(Android:创建一个圆形 TextView?)
Android - set TextView TextStyle programmatically?(Android - 以编程方式设置 TextView TextStyle?)