BLOG ARTICLE ftp | 1 ARTICLE FOUND

  1. 2012.02.07 ANT FTP Task 한글. 1

ant의 ftp task를 이용하여 여러대의 WEB/WAS 서버에 프로그램을 자동으로 배포할 수 있다. 문제는 다음과 같이 파일의 날짜가 한글로 표시되는 경우, commons-net의 ftp 모듈이 정상적으로 파일 목록을 해석하지 못하는 문제가 있어서, 파일의 날짜를 비교하여, 변경된 파일만 전송하는 기능이 제대로 동작하지 않는 현상이 발생한다.

-rw-r--r--    1 edcswas  weblogic       1159  1월 17일 23:25 .profile
lrwxrwxrwx    1 bin      bin              37  7월 23일 2010  wlmmon



이와 같은 문제를 해결하기위해서는 파일정보를 해석하는 부분의 코드와, 기본 인코딩을 조정해 주면 된다. 

commons-net의 소소코드는 다음 svn 주소에서 내려받을 수 있다.

http://svn.apache.org/repos/asf/commons/proper/net/trunk


수정이 필요한 파일은 다음과 같다.

/commons-net/src/main/java/org/apache/commons/net/ftp/FTPFileEntryParser.java

수정전

private static final String REGEX =

"([bcdelfmpSs-])"

+"(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s*"

+ "(\\d+)\\s+"                                  // link count

+ "(?:(\\S+(?:\\s\\S+)*?)\\s+)?"                // owner name (optional spaces)

+ "(?:(\\S+(?:\\s\\S+)*)\\s+)?"                 // group name (optional spaces)

+ "(\\d+(?:,\\s*\\d+)?)\\s+"                    // size or n,m

/*

* numeric or standard format date:

*   yyyy-mm-dd (expecting hh:mm to follow)

*   MMM [d]d

*   [d]d MMM

*   N.B. use non-space for MMM to allow for languages such as German which use

*   diacritics (e.g. umlaut) in some abbreviations.

*/

+ "((?:\\d+[-/]\\d+[-/]\\d+)|(?:\\S{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+\\S{3}))\\s+"

/*

  year (for non-recent standard format) - yyyy

  or time (for numeric or recent standard format) [h]h:mm

*/

+ "(\\d+(?::\\d+)?)\\s+"


+ "(\\S*)(\\s*.*)"; // the rest


수정후

private static final String REGEX =

"([bcdelfmpSs-])"

+"(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s*"

+ "(\\d+)\\s+"                                  // link count

+ "(?:(\\S+(?:\\s\\S+)*?)\\s+)?"                // owner name (optional spaces)

+ "(?:(\\S+(?:\\s\\S+)*)\\s+)?"                 // group name (optional spaces)

+ "(\\d+(?:,\\s*\\d+)?)\\s+"                    // size or n,m

/*

 * numeric or standard format date:

 *   yyyy-mm-dd (expecting hh:mm to follow)

 *   MMM [d]d

 *   [d]d MMM

 *   N.B. use non-space for MMM to allow for languages such as German which use

 *   diacritics (e.g. umlaut) in some abbreviations.

*/

+ "("

+ "(?:\\d+\\S*\\s+\\d+\\S+)|"

+ "(?:\\d+[-/]\\d+[-/]\\d+)|(?:\\S{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+\\S{3}))\\s+"

/*

   year (for non-recent standard format) - yyyy

   or time (for numeric or recent standard format) [h]h:mm

*/

+ "(\\d+(?::\\d+)?)\\s+"


+ "(\\S*)(\\s*.*)"; // the rest



/commons-net/src/main/java/org/apache/commons/net/ftp/FTP.java

수정전

public static final String DEFAULT_CONTROL_ENCODING = "ISO-8859-1";


수정후

public static final String DEFAULT_CONTROL_ENCODING = System.getProperty("file.encoding");



소스코드의 수정이 끝났으면 다음과 같이 maven을 이용하여 jar 파일을 생성한다.
   

mvn clean package -DskipTests



AND