FTPClient - Java,下载的文件大小为0 kb

时间:2012-05-16 06:25:40

标签: java file ftp download

我尝试使用此代码从我公司的ftp站点下载文件。该文件已下载但大小为0 kb。任何的想法?非常感谢 !

package org.kodejava.example.commons.net;<br/><br/>

import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
import java.io.FileOutputStream;

public class FtpDownloadDemo {
    public static void main(String[] args) {
        FTPClient client = new FTPClient();
        FileOutputStream fos = null;

        try {
            client.connect("ftp.domain.com");
            client.login("admin", "secret");

            String filename = "sitemap.xml";
            fos = new FileOutputStream(filename);

            client.retrieveFile("/" + filename, fos);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
                client.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}

0 个答案:

没有答案