001    /*
002     * Copyright (c) 2009 The openGion Project.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013     * either express or implied. See the License for the specific language
014     * governing permissions and limitations under the License.
015     */
016    package org.opengion.fukurou.util;
017    
018    import java.io.File;
019    import java.io.IOException;
020    
021    /**
022     * AbstractConnect.java ã¯ã€å?通的ã«ä½¿ç”¨ã•れã‚?ファイルä¼é?関連ã®åŸºæœ¬æ©Ÿè?を実è£?—ãŸã?Abstractクラスã§ã™ã?
023     *
024     * -host=サーãƒã? -user=ユーザー -passwd=パスワーãƒ?-remoteFile=接続å?ã®ãƒ•ァイルå?ã‚’å¿??設定ã—ã¾ã™ã?
025     * -localFile=ローカルã®ãƒ•ァイルåã?ã€å¿??ã§ã¯ã‚りã¾ã›ã‚“ãŒã?-command=DEL ã®å ´åˆã«ã®ã¿ä¸è¦ã§ã‚りã€?
026     * ãれ以外ã? command ã®å ´åˆã?ã€å¿?¦ã§ã™ã?
027     *
028     * -command=[GET/PUT/DEL/GETDIR/PUTDIR/DELDIR] ã¯ã€ã‚µãƒ¼ãƒã?ã«å¯¾ã—ã¦ã®å‡¦ç??方法をæŒ?®šã—ã¾ã™ã?
029     *   GET:サーãƒã?ã‹ã‚‰ãƒ­ãƒ¼ã‚«ãƒ«ã«ãƒ•ァイル転é€ã—ã¾ã?åˆæœŸå€¤)
030     *   PUT:ローカルファイルをサーãƒã?ã« PUT(STOREã€SAVEã€UPLOADã€ãªã©ã¨åŒæ„èª?ã—ã¾ã™ã?
031     *   DEL:サーãƒã?ã®æŒ?®šã?ファイルを削除ã—ã¾ã™ã?ã“ã?å ´åˆã?ã¿ã€?localFile 属æ?ã®æŒ?®šã?ä¸è¦ã§ã™ã?
032     *   GETDIR,PUTDIR,DELDIR:æŒ?®šã?フォルãƒ?»¥ä¸‹ã?ファイルをå?ç?—ã¾ã™ã?
033     *
034     * -mkdirs=[true/false] ã¯ã€å—ã‘å?ã®ãƒ•ァイル(GETæ™?LOCALã€PUTæ™?サーãƒã?)ã«å–り込ã‚?ƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã?
035     * 存在ã—ãªã??åˆã«ã€ä½œæ?ã™ã‚‹ã‹ã©ã?‹ã‚’指定ã—ã¾ã?åˆæœŸå€¤:true)
036     * 通常ã€ã‚µãƒ¼ãƒã?ã«ã€ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ã¦PUTã™ã‚‹å ´åˆã?å‹•çš„ã«ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ãŸã?‚±ãƒ¼ã‚¹ã§ä¾¿åˆ©ã§ã™ã?
037     * é€?«ã€ãƒ•ォルãƒ??確定ã—ã¦ãŠã‚Šã€æŒ‡å®šãƒ•ォルãƒ?»¥å¤–ã« PUT ã™ã‚‹ã®ã¯ãƒã‚°ã£ã¦ã?‚‹ã¨äº‹ãŒåˆ?‹ã£ã¦ã?‚‹å ´åˆã«ã¯
038     * false ã«è¨­å®šã—ã¦ã€å­˜åœ¨ã—ãªã?ƒ•ォルãƒ?«PUT ã—よã?¨ã™ã‚‹ã¨ã€ã‚¨ãƒ©ãƒ¼ã«ãªã‚‹ã‚ˆã?«ã—ã¾ã™ã?
039     *
040     * 引数æ–?­—å?中ã«ç©ºç™½ã‚’å«ã‚??åˆã?ã€ãƒ€ãƒ–ルコーãƒ??ション("") ã§æ‹¬ã£ã¦ä¸‹ã•ã??
041     * 引数æ–?­—å?ã® ã€?ã€ã?å‰å¾Œã«ã¯ã€ç©ºç™½ã¯æŒŸã‚ã¾ã›ã‚“。å¿?šã€?key=value ã®æ§˜ã«
042     * 繋ã’ã¦ãã ã•ã„ã€?
043     *
044     * @og.formSample
045     *  XXXConnect -host=サーãƒã? -user=ユーザー -passwd=パスワーãƒ?-remoteFile=接続å?ã®ãƒ•ァイルå?[-localFile=ローカルã®ãƒ•ァイルå]
046     *                   [-command=[GET/PUT/DEL/GETDIR/PUTDIR/DELDIR] ] [-display=[true/false] ] ・・・・
047     *
048     *    -host=サーãƒã?                    ?šæŽ¥ç¶šå?ã®ã‚µãƒ¼ãƒã?ã®ã‚¢ãƒ‰ãƒ¬ã‚¹ã¾ãŸã?ã€ã‚µãƒ¼ãƒã?å?
049     *    -user=ユーザー                    ?šæŽ¥ç¶šã™ã‚‹ãƒ¦ãƒ¼ã‚¶ãƒ¼å?
050     *    -passwd=パスワーãƒ?               ?šæŽ¥ç¶šã™ã‚‹ãƒ¦ãƒ¼ã‚¶ãƒ¼ã®ãƒ‘スワーãƒ?
051     *    -remoteFile=接続å?ã®ãƒ•ァイルå?   ?šæŽ¥ç¶šå?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ•ァイルåã?PUT,GET 関係ãªãFTPå´ã¨ã—ã¦æŒ?®šã—ã¾ã™ã?
052     *   [-localFile=ローカルã®ãƒ•ァイルå]  ?šãƒ­ãƒ¼ã‚«ãƒ«ã®ãƒ•ァイルåã?PUT,GET 関係ãªãローカルファイルを指定ã—ã¾ã™ã?
053     *   [-port=ãƒã?ãƒ?]                    ?šæŽ¥ç¶šã™ã‚‹ã‚µãƒ¼ãƒã?ã®ãƒã?トをæŒ?®šã—ã¾ã™ã?
054     *   [-command=[GET/PUT/DEL] ]          ?šã‚µãƒ¼ãƒã?å´ã§ã®å‡¦ç??方法をæŒ?®šã—ã¾ã™ã?
055     *             [GETDIR/PUTDIR/DELDIR]]          GET:FTP⇒LOCALã€PUT:LOCAL⇒FTP ã¸ã®è»¢é€ã§ã?åˆæœŸå€¤:GET)
056     *                                              DEL:FTPファイルを削除ã—ã¾ã™ã?
057     *                                              GETDIR,PUTDIR,DELDIR æŒ?®šã?フォルãƒ?»¥ä¸‹ã?ファイルをå?ç?—ã¾ã™ã?
058     *   [-mkdirs=[true/false]  ]           ?šå—ã‘å?ファイル(GETæ™?LOCALã€PUTæ™?サーãƒã?)ã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:true)
059     *                                              (false:ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªãŒç„¡ã‘れã°ã€ã‚¨ãƒ©ãƒ¼ã«ã—ã¾ã™ã?)
060     *   [-encode=エンコードå ]            ?šæ—¥æœ¬èªžãƒ•ã‚¡ã‚¤ãƒ«åãªã©ã®ã‚¨ãƒ³ã‚³ãƒ¼ãƒ‰åを指定ã—ã¾ã?åˆæœŸå€¤:Windows-31J)
061     *   [-timeout=タイãƒ?‚¢ã‚¦ãƒ?ç§’] ]       ?šDataタイãƒ?‚¢ã‚¦ãƒ?åˆæœŸå€¤:600 [ç§’])
062     *   [-display=[false/true] ]           ?štrueã¯ã€æ¤œç´¢çжæ³ã‚’表示ã—ã¾ã?åˆæœŸå€¤:false)
063     *   [-debug=[false|true]   ]           ?šãƒ‡ãƒãƒƒã‚°æƒ??を標準å?力ã«è¡¨ç¤ºã™ã‚‹(true)ã‹ã—ãªã?false)ã?åˆæœŸå€¤:false[表示ã—ãªã„])
064     *
065     * @og.rev 5.1.6.0 (2010/05/01) æ–°è¦è¿½åŠ?
066     *
067     * @version  5.0
068     * @author       Kazuhiko Hasegawa
069     * @since    JDK5.0,
070     */
071    public abstract class AbstractConnect implements ConnectIF {
072            public static final String CR = System.getProperty("line.separator");
073            private final StringBuilder errMsg = new StringBuilder( 200 );
074    
075            /** 正常フラグ  {@value} */
076            public static final boolean FLAG_OK = true;
077            /** 異常フラグ  {@value} */
078            public static final boolean FLAG_NG = false;
079            /** Dataタイãƒ?‚¢ã‚¦ãƒ?åˆæœŸå€¤:{@value} [ç§’]) */
080            public static final int         TIMEOUT = 600 ;
081    
082            /** サーãƒã? */
083            protected String        host            = null;                 // サーãƒã?
084            /** ユーザー */
085            protected String        user            = null;                 // ユーザー
086            /** パスワー�*/
087            protected String        passwd          = null;                 // パスワー�
088            /** ãƒã?ãƒ?*/
089            protected String        port            = null;                 // ãƒã?ãƒ?
090    
091            /** ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ */
092            protected boolean       isMkdirs        = true;                 // å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ã€‚true:作æ?ã™ã‚‹ / false:ç„¡ã‘れã°ã‚¨ãƒ©ãƒ¼
093            /** Dataタイãƒ?‚¢ã‚¦ãƒ? */
094            protected int           timeout         = TIMEOUT;              // Dataタイãƒ?‚¢ã‚¦ãƒ?åˆæœŸå€¤:600 [ç§’])
095            /** 検索状æ³ã‚’表示ã™ã‚‹ã‹ã©ã?‹  */
096            protected boolean       isDisplay       = false;                // trueã¯ã€æ¤œç´¢çжæ³ã‚’表示ã—ã¾ã?åˆæœŸå€¤:false)
097            /** ãƒ?ƒãƒ?‚°æƒ??を表示ã™ã‚‹ã‹ã©ã?‹  */
098            protected boolean       isDebug         = false;                // ãƒ?ƒãƒ?‚°æƒ??を標準å?力ã«è¡¨ç¤ºã™ã‚‹(true)ã‹ã—ãªã?false)ã?
099    
100            /**
101             * サーãƒã?ã¸ã®æŽ¥ç¶šã?ログインを行ã„ã¾ã™ã?
102             */
103            @Override
104            public abstract void connect() ;
105    
106            /**
107             * command , localFile , remoteFile ã‚’å?ã«ã€FTP処ç?‚’行ã„ã¾ã™ã?
108             *
109             * ã“ã?メソãƒ?ƒ‰ã¯ã€connect( String , String , String )メソãƒ?ƒ‰ã€ãŠã‚ˆã?ã€?
110             * paramInit() 実行後ã«ã€å‘¼ã³å‡ºã™å¿?¦ãŒã‚りã¾ã™ã?
111             *
112             * ※ å†?ƒ¨ã§ã€command ã«æŒ?®šã§ããªã??ã‚’ã‚»ãƒ?ƒˆã—ãŸã‹ã?何らã‹ã?エラーãŒç™ºç”Ÿã—ãŸå?åˆã?
113             *
114             * @param       command GET:HOST⇒LOCAL ã€PUT:LOCAL⇒HOST ã€DEL:HOSTファイルを削除
115             * @param       localFile       ローカルã®ãƒ•ァイルå?
116             * @param       remoteFile      HOST接続å?ã®ãƒ•ァイルå?
117             */
118            @Override
119            public void action( final String command, final String localFile, final String remoteFile ) {
120                    String rmtFile = remoteFile.replace( '\\','/' );
121                    if( isDisplay ) {
122                            System.out.println( "ACTION: command=" + command + ",localFile=" + localFile + ",remoteFile=" + rmtFile );
123                    }
124    
125                    try {
126                            // 実際ã®å‡¦ç?‚’行ã„ã¾ã™ã?(GET/PUT/DEL)
127                            if( "GET".equals( command ) ) {
128                                    actionGET( localFile, rmtFile );
129                            }
130                            else if( "PUT".equals( command ) ) {
131                                    actionPUT( localFile, rmtFile );
132                            }
133                            else if( "DEL".equals( command ) ) {
134                                    actionDEL( rmtFile );
135                            }
136                            else if( "GETDIR".equals( command ) ) {
137                                    actionGETdir( localFile, rmtFile );
138                            }
139                            else if( "PUTDIR".equals( command ) ) {
140                                    actionPUTdir( localFile, rmtFile );
141                            }
142                            else if( "DELDIR".equals( command ) ) {
143                                    actionDELdir( rmtFile );
144                            }
145                            else {
146                                    errAppend( "commandã¯ã€GET/PUT/DEL/GETDIR/PUTDIR/DELDIR ã‹ã‚‰æŒ?®šãã?•ã??" );
147                                    errAppend( "   command    = [" , command , "]" );
148                                    throw new RuntimeException(  getErrMsg() );
149                            }
150                    }
151                    catch( Exception ex ) {
152                            errAppend( "Server action Error." );
153                            errAppend( "   command    = [" , command        , "]" );
154                            errAppend( "   localFile  = [" , localFile      , "]" );
155                            errAppend( "   remoteFile = [" , remoteFile , "]" );
156                            errAppend( ex.getMessage() );
157                            if( isDebug ) { ex.printStackTrace(); }
158                            throw new RuntimeException( getErrMsg(),ex );
159                    }
160            }
161    
162            /**
163             * サーãƒã?ã¨ã®æŽ¥ç¶šã‚’クローズã—ã¾ã™ã?
164             *
165             * ログインã•れã¦ã?‚‹å ´åˆã?ã€ãƒ­ã‚°ã‚¢ã‚¦ãƒˆã‚‚行ã„ã¾ã™ã?
166             * コãƒã‚¯ãƒˆã•れã¦ã?‚‹å ´åˆã?ã€ãƒ‡ã‚£ã‚¹ã‚³ãƒã‚¯ãƒˆã—ã¾ã™ã?
167             */
168            @Override
169            public abstract void disconnect();
170    
171            /**
172             * command="GET" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
173             *
174             * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ•ァイルåをローカルã«ãƒ?‚¦ãƒ³ãƒ­ãƒ¼ãƒ‰ã—ã¾ã™ã?
175             *
176             * @param       localFile       ローカルã®ãƒ•ァイルå?
177             * @param       remoteFile      接続å?ã®ãƒ•ァイルå?
178             * @throws Exception 何らã‹ã?エラーãŒç™ºç”Ÿã—ãŸå?åˆã?
179             */
180            protected abstract void actionGET( final String localFile, final String remoteFile ) throws Exception ;
181    
182            /**
183             * command="GETDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
184             *
185             * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªä»¥ä¸‹ã‚’ローカルãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«éšŽå±¤æ§‹é?ã®ã¾ã¾ãƒ?‚¦ãƒ³ãƒ­ãƒ¼ãƒ‰ã—ã¾ã™ã?
186             *
187             * @param       localDir        ローカルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
188             * @param       remoteDir       接続å?ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
189             * @throws Exception 何らã‹ã?エラーãŒç™ºç”Ÿã—ãŸå?åˆã?
190             */
191            protected abstract void actionGETdir( final String localDir, final String remoteDir ) throws Exception ;
192    
193            /**
194             * command="PUT" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
195             *
196             * ローカルファイルをã?接続å?ã®ã‚µãƒ¼ãƒã?å´ã«ã‚¢ãƒ??ロードã—ã¾ã™ã?
197             *
198             * @param       localFile       ローカルã®ãƒ•ァイルå?
199             * @param       remoteFile      接続å?ã®ãƒ•ァイルå?
200             * @throws Exception 何らã‹ã?エラーãŒç™ºç”Ÿã—ãŸå?åˆã?
201             */
202            protected abstract void actionPUT( final String localFile, final String remoteFile ) throws Exception ;
203    
204            /**
205             * command="PUTDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
206             *
207             * ローカルファイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªä»¥ä¸‹ã‚’ã€æŽ¥ç¶šå?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«éšŽå±¤æ§‹é?ã®ã¾ã¾ã‚¢ãƒ??ロードã—ã¾ã™ã?
208             *
209             * @og.rev 5.3.7.0 (2011/07/01) フォルãƒ?«ã‚¢ã‚¯ã‚»ã‚¹ã§ããªã??åˆã?ã€ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã¾ã™ã?
210             *
211             * @param       localDir        ローカルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
212             * @param       remoteDir       接続å?ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
213             * @throws Exception  何らã‹ã?エラーãŒç™ºç”Ÿã—ãŸå?åˆã?
214             */
215            protected void actionPUTdir( final String localDir, final String remoteDir ) throws Exception {
216                    File[] lclFiles = new File( localDir ).listFiles();
217    
218                    // 5.3.7.0 (2011/07/01) フォルãƒ?«ã‚¢ã‚¯ã‚»ã‚¹ã§ããªã??åˆã?ã€ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã¾ã™ã?
219                    if( lclFiles == null ) {
220                            errAppend( "æŒ?®šã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¯ã€ã‚¢ã‚¯ã‚»ã‚¹ã§ãã¾ã›ã‚“ã€? );
221                            errAppend( "   localDir   = [" , localDir       , "]" );
222                            throw new RuntimeException( getErrMsg() );
223                    }
224    
225                    for( int i=0; i<lclFiles.length; i++ ) {
226                            String lcl = lclFiles[i].getName();
227                            if( lclFiles[i].isDirectory() ) {
228                                    actionPUTdir( addFile( localDir,lcl ),addFile( remoteDir,lcl ) );
229                            }
230                            else {
231                                    actionPUT( addFile( localDir,lcl ),addFile( remoteDir,lcl ) );
232                            }
233                    }
234            }
235    
236            /**
237             * command="DEL" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
238             *
239             * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ•ァイルåを削除ã—ã¾ã™ã?
240             *
241             * @param       remoteFile      接続å?ã®ãƒ•ァイルå?
242             * @throws Exception 何らã‹ã?エラーãŒç™ºç”Ÿã—ãŸå?åˆã?
243             */
244            protected abstract void actionDEL( final String remoteFile ) throws Exception ;
245    
246            /**
247             * command="DELDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
248             *
249             * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªåを削除ã—ã¾ã™ã?
250             *
251             * @param       remoteDir       接続å?ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
252             * @throws Exception 何らã‹ã?エラーãŒç™ºç”Ÿã—ãŸå?åˆã?
253             */
254            protected abstract void actionDELdir( final String remoteDir ) throws Exception ;
255    
256            /**
257             * ローカルファイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã—ã¾ã™ã?
258             *
259             * 引数ã®ãƒ•ァイルåã?ã€ãƒ•ァイルåã§ã™ã?作æ?ã™ã‚‹ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¯ã€ãã®ãƒ•ァイルオブジェクトã?
260             * getParentFile() ã§å–å¾—ã•れるãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¾ã§ã‚’作æ?ã—ã¾ã™ã?
261             *
262             * ※ ローカルファイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã®ä½œæ?ã«å¤±æ•—ã—ãŸå?åˆã?ã€RuntimeException ã?throw ã•れã¾ã™ã?
263             *
264             * @param       localFile       ローカルã®ãƒ•ァイルå?
265             * @throws IOException File#getCanonicalFile() ã§ç™ºç”Ÿã™ã‚‹å?出力エラー
266             */
267            protected void makeLocalDir( final String localFile ) throws IOException {
268                    File fileDir = new File( localFile ).getCanonicalFile().getParentFile();
269                    if( !fileDir.exists() ) {
270                            if( ! fileDir.mkdirs() ) {
271                                    errAppend( "ローカルファイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã®ä½œæ?ã«å¤±æ•—ã—ã¾ã—ãŸã€? );
272                                    errAppend( "   localFile   = [" , localFile     , "]" );
273                                    throw new RuntimeException( getErrMsg() );
274                            }
275                    }
276            }
277    
278            /**
279             * ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¨ãƒ•ァイルåã‚’åˆæ?ã—ã¾ã™ã?
280             *
281             * å˜ç´”ã«ã€ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®æœ?¾Œã¨ã€ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ??ã®ã€?/" ã‚’ãƒã‚§ãƒ?‚¯ã—ã?
282             * 存在ã™ã‚Œã°ã€ãã®ã¾ã¾ã€çµåˆã—ã?存在ã—ãªã‘れã°ã€?/" を追åŠ?—ã¾ã™ã?
283             * 両方ã«å­˜åœ¨ã™ã‚‹å ´åˆã?ã€ç‰‡æ–¹ã‚’ã?ãšã—ã¾ã™ã?
284             *
285             * @param       dir     ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
286             * @param       file    ファイルå?
287             *
288             * @return      åˆæ?ã•れãŸãƒ•ァイルå?
289             */
290            protected String addFile( final String dir,final String file ) {
291                    final String filepath ;
292    
293                    char ch1 = dir.charAt( dir.length()-1 ) ;       // ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã®æœ?¾Œã?æ–?­?
294                    char ch2 = file.charAt( 0 ) ;                           // ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ??ã®æ–?­?
295    
296                    if( ch1 == '/' || ch1 == '\\' ) {
297                            if( ch2 == '/' || ch2 == '\\' ) {       // 両方ã¨ã‚‚存在ã™ã‚‹ã€?
298                                    filepath = dir + file.substring(1);
299                            }
300                            else {
301                                    filepath = dir + file;
302                            }
303                    }
304                    else {
305                            if( ch2 == '/' || ch2 == '\\' ) {       // ç‰?–¹ã®ã¿å­˜åœ¨ã™ã‚‹ã€?
306                                    filepath = dir + file;
307                            }
308                            else {
309                                    filepath = dir + "/" + file;
310                            }
311                    }
312    
313                    return filepath ;
314            }
315    
316            /**
317             * サーãƒã?ã®ã€ã?ストã?ユーザーã€ãƒ‘スワードを設定ã—ã¾ã™ã?
318             *
319             * @param       host    サーãƒã?
320             * @param       user    ユーザー
321             * @param       passwd  パスワー�
322             */
323            @Override
324            public void setHostUserPass( final String host , final String user , final String passwd ) {
325                    this.host = host;
326                    this.user = user;
327                    this.passwd = passwd;
328            }
329    
330            /**
331             * サーãƒã?åã‚’å–å¾—ã—ã¾ã™ã?
332             *
333             * @return      サーãƒã?
334             */
335    //      protected String getHost() { return host; }
336    
337            /**
338             * ユーザーåã‚’å–å¾—ã—ã¾ã™ã?
339             *
340             * @return      ユーザー
341             */
342    //      protected String getUser() { return user; }
343    
344            /**
345             * パスワードをå–å¾—ã—ã¾ã™ã?
346             *
347             * @return      パスワー�
348             */
349    //      protected String getPassword() { return passwd; }
350    
351            /**
352             * 接続ã«åˆ©ç”¨ã™ã‚‹ãƒã?ト番å·ã‚’設定ã—ã¾ã™ã?
353             *
354             * @param       port    接続ã«åˆ©ç”¨ã™ã‚‹ãƒã?ト番å·
355             */
356            @Override
357            public void setPort( final String port ) {
358                    if( port != null ) {
359                            this.port = port ;
360                    }
361            }
362    
363            /**
364             * ãƒã?トをå–å¾—ã—ã¾ã™ã?
365             * 設定ã•れã¦ã?‚‹ç”Ÿã?port属æ?(nullã‚‚ã‚りã†ã‚?ã‚’è¿”ã—ã¾ã™ã?
366             *
367             * @return      ãƒã?ãƒ?
368             */
369            protected String getPort() { return port; }
370    
371            /**
372             * ãƒã?トをå–å¾—ã—ã¾ã™ã?
373             * 設定ã•れã¦ã?‚‹port属æ?ãŒã?nullã®å ´åˆã?ã€defPortã‚’è¿”ã—ã¾ã™ã?
374             *
375             * @param       defPort port ã?null ã®å ´åˆã?åˆæœŸå€¤
376             *
377             * @return      ãƒã?ãƒ?
378             */
379            protected int getPort( final int defPort) {
380                    return ( port == null ) ? defPort : Integer.parseInt( port );
381            }
382    
383            /**
384             * ãれãžã‚Œã®å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:true:作æ?ã™ã‚‹)ã€?
385             *
386             * -mkdirs=[true/false] ã¯ã€å—ã‘å?ã®ãƒ•ァイル(GETæ™?LOCALã€PUTæ™?サーãƒã?)ã«å–り込ã‚?ƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã?
387             * 存在ã—ãªã??åˆã«ã€ä½œæ?ã™ã‚‹ã‹ã©ã?‹ã‚’指定ã—ã¾ã?åˆæœŸå€¤:true)
388             * 通常ã€ã‚µãƒ¼ãƒã?ã«ã€ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ã¦PUTã™ã‚‹å ´åˆã?å‹•çš„ã«ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ãŸã?‚±ãƒ¼ã‚¹ã§ä¾¿åˆ©ã§ã™ã?
389             * é€?«ã€ãƒ•ォルãƒ??確定ã—ã¦ãŠã‚Šã€æŒ‡å®šãƒ•ォルãƒ?»¥å¤–ã« PUT ã™ã‚‹ã®ã¯ãƒã‚°ã£ã¦ã?‚‹ã¨äº‹ãŒåˆ?‹ã£ã¦ã?‚‹å ´åˆã«ã¯
390             * false ã«è¨­å®šã—ã¦ã€å­˜åœ¨ã—ãªã?ƒ•ォルãƒ?«PUT ã—よã?¨ã™ã‚‹ã¨ã€ã‚¨ãƒ©ãƒ¼ã«ãªã‚‹ã‚ˆã?«ã—ã¾ã™ã?
391             *
392             * @param       isMkdirs        å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ã€‚true:作æ?ã™ã‚‹
393             */
394            @Override
395            public void setMkdirs( final boolean isMkdirs ) {
396                    this.isMkdirs = isMkdirs ;
397            }
398    
399            /**
400             * å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ã‚’å–å¾—ã—ã¾ã™ã?
401             *
402             * @return      å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ã€‚true:作æ?ã™ã‚‹
403             */
404    //      protected boolean isMkdirs() { return isMkdirs; }
405    
406            /**
407             * タイãƒ?‚¢ã‚¦ãƒˆã‚’ç§’ã§æŒ?®šã—ã¾ã?åˆæœŸå€¤:600 [ç§’])ã€?
408             *
409             * オリジナル㮠FTPClient#setDataTimeout( int ) ã¯ã€ãƒŸãƒªç§’ã§ã‚»ãƒ?ƒˆ
410             * ã—ã¾ã™ãŒã€ã“ã“ã?メソãƒ?ƒ‰ã§ã¯ã€ç§’ã§ã‚»ãƒ?ƒˆã—ã¾ã™ã?
411             *
412             * @param       timeout タイãƒ?‚¢ã‚¦ãƒ?ç§’]
413             * @throws RuntimeException タイãƒ?‚¢ã‚¦ãƒˆã?æŒ?®šãŒå¤§ãã™ãŽãŸå ´å?
414             */
415            @Override
416            public void setTimeout( final int timeout ) {
417                    if( Integer.MAX_VALUE / 1000 < timeout ) {
418                            errAppend( "タイãƒ?‚¢ã‚¦ãƒˆã?æŒ?®šãŒå¤§ãã™ãŽã¾ã™ã?" );
419                            errAppend( "   timeout   = [" , timeout , "]" );
420                            throw new RuntimeException( getErrMsg() );
421                    }
422    
423                    this.timeout = timeout ;
424            }
425    
426            /**
427             *æŒ?®šã•れãŸã‚¿ã‚¤ãƒ?‚¢ã‚¦ãƒˆã‚’ç§’ã§å–å¾—ã—ã¾ã?åˆæœŸå€¤:600 [ç§’])ã€?
428             *
429             * @return      タイãƒ?‚¢ã‚¦ãƒ?ç§’]
430             */
431    //      protected int getTimeout() { return timeout; }
432    
433            /**
434             * 実行状æ³ã?表示å¯å¦ を設定ã—ã¾ã?åˆæœŸå€¤:false:表示ã—ãªã?ã€?
435             *
436             * @param       isDisplay       実行状æ³ã?表示å¯å¦
437             */
438            @Override
439            public void setDisplay( final boolean isDisplay ) {
440                    this.isDisplay = isDisplay ;
441            }
442    
443            /**
444             * 実行状æ³ã?表示å¯å¦ã‚’å–å¾—ã—ã¾ã™ã?
445             *
446             * @return      実行状æ³ã?表示å¯å¦
447             */
448    //      protected boolean isDisplay() { return isDisplay; }
449    
450            /**
451             * ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦ を設定ã—ã¾ã?åˆæœŸå€¤:false:表示ã—ãªã?ã€?
452             *
453             * @param       isDebug ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦
454             */
455            @Override
456            public void setDebug( final boolean isDebug ) {
457                    this.isDebug = isDebug ;
458            }
459    
460            /**
461             * ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦ ã‚’å–å¾—ã—ã¾ã™ã?
462             *
463             * @return      ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦
464             */
465    //      protected boolean isDebug() { return isDebug; }
466    
467            /**
468             * 処ç?¸­ã«ç™ºç”Ÿã—ãŸã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
469             *
470             * @param       msg  メãƒ?‚»ãƒ¼ã‚¸åŒ–ã—ãŸã„オブジェクãƒ?
471             */
472            protected void errAppend( final Object msg ) {
473                    errMsg.append( String.valueOf(msg) ).append( CR );
474            }
475    
476            /**
477             * 処ç?¸­ã«ç™ºç”Ÿã—ãŸã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
478             *
479             * @param       msgs  Object...
480             */
481            protected void errAppend( final Object... msgs ) {
482                    for( int i=0; i<msgs.length; i++ ) {
483                            errMsg.append( String.valueOf(msgs[i]) );
484                    }
485    
486                    errMsg.append( CR );
487            }
488    
489            /**
490             * 処ç?¸­ã«ç™ºç”Ÿã—ãŸã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’å–りå?ã—ã¾ã™ã?
491             *
492             * @return      エラーメãƒ?‚»ãƒ¼ã‚¸
493             */
494            @Override
495            public String getErrMsg() {
496                    return errMsg.toString();
497            }
498    }