본문 바로가기
프로그래밍/JAVA, JSP

자바(JAVA) FTP 파일 전송

by 착살의 숲 2013. 11. 13.
반응형

※ 파일 전송

 

public boolean setVoiceFtpPut() {

boolean result = false;

FTPClient ftp = null;

int reply = 0;

 

try {

ftp = new FTPClient();

ftp.setControlEncoding("UTF-8");

ftp.connect("IP", port);

 

reply = ftp.getReplyCode();

 

if(!FTPReply.isPositiveCompletion(reply)){

  ftp.disconnect();

return result;

}

 

if(!ftp.login("아이디", "패스워드")){

  ftp.logout();

  return result;

}

 

ftp.setFileType(FTP.BINARY_FILE_TYPE);

 

String fileName = "파일명";

 

File uploadFile = new File(fileName);

FileInputStream fis = null;

 

try{

fis = new FileInputStream(uploadFile);

boolean ftpSuccess = ftp.storeFile(uploadFile.getName(), fis);

 

if(ftpSuccess){

System.out.println("FTP 성공..!!");

}

 

}catch (Exception e) {

// TODO: handle exception

}finally{

if(fis != null) fis.close();

}

 

ftp.logout();

result = true;

 

} catch (SocketException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

if(ftp != null && ftp.isConnected()){

try {

ftp.disconnect();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

 

return result;

}

 

 

반응형

댓글