|
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
public class TestFtp {
public static void main(String[] args) {
FTPClient ftpClient = new FTPClient();
FileOutputStream fos = null;
String dir = "e:/oracle_log/" ;
try {
ftpClient.connect("192.168.1.124");
ftpClient.login("oracle", "oracle");
ftpClient.setBufferSize(1024);
String remoteFileName = "/opt/oracle/admin/orcl/bdump/";
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
FTPFile[] ftpF = ftpClient.listFiles(remoteFileName) ;
for(FTPFile f : ftpF) {
System.out.println(f.getName()) ;
fos = new FileOutputStream(dir+f.getName());
ftpClient.retrieveFile(remoteFileName+f.getName(), fos);
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
} |
|
|