<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="org.apache.commons.net.ftp.*" %>
<%
FTPClient ftp = null;
try{
String FilePath="";
FilePath=request.getParameter("FilePath");
ftp = new FTPClient();
ftp.setControlEncoding("UTF-8");
ftp.connect("아이피");
ftp.login("아이디", "패스워드");
ftp.changeWorkingDirectory("/vms/"); // 디렉토리 변경
File uploadFile = new File(FilePath);
FileInputStream fis = null;
try{
fis = new FileInputStream(uploadFile);
boolean isSuccess = ftp.storeFile(uploadFile.getName(), fis);
if (isSuccess)
{
System.out.println("Upload Success");
}
} catch (IOException ex){
System.out.println(ex.getMessage());
} finally{
if (fis != null)
try{
fis.close();
} catch (IOException ex) {}
}
ftp.logout();
} catch (SocketException e){
System.out.println("Socket:" + e.getMessage());
} catch (IOException e){
System.out.println("IO:" + e.getMessage());
} finally{
if (ftp != null && ftp.isConnected()){
try{
ftp.disconnect();
} catch (IOException e){}
}
}
%>
[Jsp] FTP 업로드 예제
2011. 6. 2. 21:50