Java从FTP空文本文件下载文本文件

时间:2013-12-02 21:00:59

标签: java ftp

您好我正在尝试让我的程序从我的FTP服务器下载文本文档。

这是代码:

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.net.ftp.FTPClient;

public class NetTestFTP {
    public static void main(String[] args) {
        FTPClient client = new FTPClient();
        OutputStream outStream;
        try {
            client.connect("82.44.221.198");
            client.login("User", "Pass");
            String remoteFile = "/hello.txt";
            outStream = new FileOutputStream("hello.txt");
            client.retrieveFile(remoteFile, outStream);
        } catch (IOException ioe) {
            System.out.println("Error communicating with FTP server.");
        } finally {
            try {
                client.disconnect();
            } catch (IOException e) {
                System.out.println("Problem disconnecting from FTP server");
            }
        }

    }
}

0 个答案:

没有答案