您好我正在尝试让我的程序从我的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");
}
}
}
}