FTP를 이용한 다운로드
/* 자세히 알아보진 않았는데 FTPClient 객체를 제공하는 jar가있고 FtpClient 객체를 제공하는 jar가 있는것 같다. 서로 제공하는 내용이 약간 다르니 참고하는 분들은 FTP인지 Ftp인지 잘 확인하기바람.*/
//일반파일 경로
StringBuffer ftpFilePath = new StringBuffer(); //다운로드받을 파일이 있는경로
ftpFilePath.append(ConfigProperties.getProperty("download.path") + "/hub");
ftpFilePath.append("/FILE/TEXT/admbrd/" + request.getParameter("portal_cd"));
FtpClient client = new FtpClient(); //FtpClient 객체 생성client.openServer(ConfigProperties.getProperty("webtob.ftp.url"), 21); //호스트IP, 포트번호
client.login(ID, PassWord); //로그인 가능한 ID, PW 설정
BufferedOutputStream outs = null;
TelnetInputStream fileIs = null;
try{
client.cd(ftpFilePath.toString()); //해당경로로 이동
client.binary();
fileIs = client.get(파일명); //이동한 경로에 존재하는 파일명
outs = new BufferedOutputStream(response.getOutputStream());
byte bytes[] = new byte[1024];
int c;
request.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(파일명, "utf-8") + ";"); //파일명 인코딩 설정
while ((c = fileIs.read(bytes)) != -1){
outs.write(bytes, 0, c);
}catch(Exception e){
}finally{
if(fileIs != null){
fileIs.close();
}
if(imgIs != null){
imgIs.close();
}
if(outs != null){
outs.close();
}
client.closeServer();
}