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 * @param command GET:HOST⇒LOCAL ã€PUT:LOCAL⇒HOST ã€DEL:HOSTファイルを削除
113 * @param localFile ãƒãƒ¼ã‚«ãƒ«ã®ãƒ•ァイルå?
114 * @param remoteFile HOST接続å?ã®ãƒ•ァイルå?
115 * @throws RuntimeException
116 */
117 @Override
118 public void action( final String command, final String localFile, final String remoteFile ) {
119 String rmtFile = remoteFile.replace( '\\','/' );
120 if( isDisplay ) {
121 System.out.println( "ACTION: command=" + command + ",localFile=" + localFile + ",remoteFile=" + rmtFile );
122 }
123
124 try {
125 // 実際ã®å‡¦ç?‚’行ã„ã¾ã™ã?(GET/PUT/DEL)
126 if( "GET".equals( command ) ) {
127 actionGET( localFile, rmtFile );
128 }
129 else if( "PUT".equals( command ) ) {
130 actionPUT( localFile, rmtFile );
131 }
132 else if( "DEL".equals( command ) ) {
133 actionDEL( rmtFile );
134 }
135 else if( "GETDIR".equals( command ) ) {
136 actionGETdir( localFile, rmtFile );
137 }
138 else if( "PUTDIR".equals( command ) ) {
139 actionPUTdir( localFile, rmtFile );
140 }
141 else if( "DELDIR".equals( command ) ) {
142 actionDELdir( rmtFile );
143 }
144 else {
145 errAppend( "commandã¯ã€GET/PUT/DEL/GETDIR/PUTDIR/DELDIR ã‹ã‚‰æŒ?®šãã?•ã??" );
146 errAppend( " command = [" , command , "]" );
147 throw new RuntimeException( getErrMsg() );
148 }
149 }
150 catch( Exception ex ) {
151 errAppend( "Server action Error." );
152 errAppend( " command = [" , command , "]" );
153 errAppend( " localFile = [" , localFile , "]" );
154 errAppend( " remoteFile = [" , remoteFile , "]" );
155 errAppend( ex.getMessage() );
156 if( isDebug ) { ex.printStackTrace(); }
157 throw new RuntimeException( getErrMsg(),ex );
158 }
159 }
160
161 /**
162 * サーãƒã?ã¨ã®æŽ¥ç¶šã‚’クãƒãƒ¼ã‚ºã—ã¾ã™ã?
163 *
164 * ãƒã‚°ã‚¤ãƒ³ã•れã¦ã?‚‹å ´åˆã?ã€ãƒã‚°ã‚¢ã‚¦ãƒˆã‚‚行ã„ã¾ã™ã?
165 * コãƒã‚¯ãƒˆã•れã¦ã?‚‹å ´åˆã?ã€ãƒ‡ã‚£ã‚¹ã‚³ãƒã‚¯ãƒˆã—ã¾ã™ã?
166 */
167 @Override
168 public abstract void disconnect();
169
170 /**
171 * command="GET" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
172 *
173 * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ•ァイルåã‚’ãƒãƒ¼ã‚«ãƒ«ã«ãƒ?‚¦ãƒ³ãƒãƒ¼ãƒ‰ã—ã¾ã™ã?
174 *
175 * @param localFile ãƒãƒ¼ã‚«ãƒ«ã®ãƒ•ァイルå?
176 * @param remoteFile 接続å?ã®ãƒ•ァイルå?
177 * @throws Exception
178 */
179 protected abstract void actionGET( final String localFile, final String remoteFile ) throws Exception ;
180
181 /**
182 * command="GETDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
183 *
184 * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªä»¥ä¸‹ã‚’ãƒãƒ¼ã‚«ãƒ«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«éšŽå±¤æ§‹é?ã®ã¾ã¾ãƒ?‚¦ãƒ³ãƒãƒ¼ãƒ‰ã—ã¾ã™ã?
185 *
186 * @param localDir ãƒãƒ¼ã‚«ãƒ«ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
187 * @param remoteDir 接続å?ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
188 * @throws IOException
189 */
190 protected abstract void actionGETdir( final String localDir, final String remoteDir ) throws Exception ;
191
192 /**
193 * command="PUT" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
194 *
195 * ãƒãƒ¼ã‚«ãƒ«ãƒ•ァイルをã?接続å?ã®ã‚µãƒ¼ãƒã?å´ã«ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã—ã¾ã™ã?
196 *
197 * @param localFile ãƒãƒ¼ã‚«ãƒ«ã®ãƒ•ァイルå?
198 * @param remoteFile 接続å?ã®ãƒ•ァイルå?
199 * @throws Exception
200 */
201 protected abstract void actionPUT( final String localFile, final String remoteFile ) throws Exception ;
202
203 /**
204 * command="PUTDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
205 *
206 * ãƒãƒ¼ã‚«ãƒ«ãƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªä»¥ä¸‹ã‚’ã€æŽ¥ç¶šå?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«éšŽå±¤æ§‹é?ã®ã¾ã¾ã‚¢ãƒ??ãƒãƒ¼ãƒ‰ã—ã¾ã™ã?
207 *
208 * @og.rev 5.3.7.0 (2011/07/01) フォルãƒ?«ã‚¢ã‚¯ã‚»ã‚¹ã§ããªã??åˆã?ã€ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã¾ã™ã?
209 *
210 * @param localDir ãƒãƒ¼ã‚«ãƒ«ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
211 * @param remoteDir 接続å?ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
212 * @throws Exception
213 */
214 protected void actionPUTdir( final String localDir, final String remoteDir ) throws Exception {
215 File[] lclFiles = new File( localDir ).listFiles();
216
217 // 5.3.7.0 (2011/07/01) フォルãƒ?«ã‚¢ã‚¯ã‚»ã‚¹ã§ããªã??åˆã?ã€ã‚¨ãƒ©ãƒ¼ã‚’è¿”ã—ã¾ã™ã?
218 if( lclFiles == null ) {
219 errAppend( "æŒ?®šã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¯ã€ã‚¢ã‚¯ã‚»ã‚¹ã§ãã¾ã›ã‚“ã€? );
220 errAppend( " localDir = [" , localDir , "]" );
221 throw new RuntimeException( getErrMsg() );
222 }
223
224 for( int i=0; i<lclFiles.length; i++ ) {
225 String lcl = lclFiles[i].getName();
226 if( lclFiles[i].isDirectory() ) {
227 actionPUTdir( addFile( localDir,lcl ),addFile( remoteDir,lcl ) );
228 }
229 else {
230 actionPUT( addFile( localDir,lcl ),addFile( remoteDir,lcl ) );
231 }
232 }
233 }
234
235 /**
236 * command="DEL" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
237 *
238 * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ•ァイルåを削除ã—ã¾ã™ã?
239 *
240 * @param remoteFile 接続å?ã®ãƒ•ァイルå?
241 * @throws Exception
242 */
243 protected abstract void actionDEL( final String remoteFile ) throws Exception ;
244
245 /**
246 * command="DELDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
247 *
248 * 接続å?ã®ã‚µãƒ¼ãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªåを削除ã—ã¾ã™ã?
249 *
250 * @param remoteDir 接続å?ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
251 * @throws Exception
252 */
253 protected abstract void actionDELdir( final String remoteDir ) throws Exception ;
254
255 /**
256 * ãƒãƒ¼ã‚«ãƒ«ãƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã—ã¾ã™ã?
257 *
258 * 引数ã®ãƒ•ァイルåã?ã€ãƒ•ァイルåã§ã™ã?作æ?ã™ã‚‹ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¯ã€ãã®ãƒ•ァイルオブジェクトã?
259 * getParentFile() ã§å–å¾—ã•れるãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¾ã§ã‚’作æ?ã—ã¾ã™ã?
260 *
261 * @param localFile ãƒãƒ¼ã‚«ãƒ«ã®ãƒ•ァイルå?
262 * @throws IOException , RuntimeException
263 */
264 protected void makeLocalDir( final String localFile ) throws IOException {
265 File fileDir = new File( localFile ).getCanonicalFile().getParentFile();
266 if( !fileDir.exists() ) {
267 if( ! fileDir.mkdirs() ) {
268 errAppend( "ãƒãƒ¼ã‚«ãƒ«ãƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã®ä½œæ?ã«å¤±æ•—ã—ã¾ã—ãŸã€? );
269 errAppend( " localFile = [" , localFile , "]" );
270 throw new RuntimeException( getErrMsg() );
271 }
272 }
273 }
274
275 /**
276 * ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã¨ãƒ•ァイルåã‚’åˆæ?ã—ã¾ã™ã?
277 *
278 * å˜ç´”ã«ã€ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã®æœ?¾Œã¨ã€ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ??ã®ã€?/" ã‚’ãƒã‚§ãƒ?‚¯ã—ã?
279 * å˜åœ¨ã™ã‚Œã°ã€ãã®ã¾ã¾ã€çµåˆã—ã?å˜åœ¨ã—ãªã‘れã°ã€?/" を追åŠ?—ã¾ã™ã?
280 * 両方ã«å˜åœ¨ã™ã‚‹å ´åˆã?ã€ç‰‡æ–¹ã‚’ã?ãšã—ã¾ã™ã?
281 *
282 * @param dir ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
283 * @param file ファイルå?
284 *
285 * @return åˆæ?ã•れãŸãƒ•ァイルå?
286 */
287 protected String addFile( final String dir,final String file ) {
288 final String filepath ;
289
290 char ch1 = dir.charAt( dir.length()-1 ) ; // ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã®æœ?¾Œã?æ–??
291 char ch2 = file.charAt( 0 ) ; // ãƒ•ã‚¡ã‚¤ãƒ«ã®æœ??ã®æ–??
292
293 if( ch1 == '/' || ch1 == '\\' ) {
294 if( ch2 == '/' || ch2 == '\\' ) { // 両方ã¨ã‚‚å˜åœ¨ã™ã‚‹ã€?
295 filepath = dir + file.substring(1);
296 }
297 else {
298 filepath = dir + file;
299 }
300 }
301 else {
302 if( ch2 == '/' || ch2 == '\\' ) { // ç‰?–¹ã®ã¿å˜åœ¨ã™ã‚‹ã€?
303 filepath = dir + file;
304 }
305 else {
306 filepath = dir + "/" + file;
307 }
308 }
309
310 return filepath ;
311 }
312
313 /**
314 * サーãƒã?ã®ã€ã?ストã?ユーザーã€ãƒ‘スワードをè¨å®šã—ã¾ã™ã?
315 *
316 * @param host サーãƒã?
317 * @param user ユーザー
318 * @param passwd パスワー�
319 */
320 @Override
321 public void setHostUserPass( final String host , final String user , final String passwd ) {
322 this.host = host;
323 this.user = user;
324 this.passwd = passwd;
325 }
326
327 /**
328 * サーãƒã?åã‚’å–å¾—ã—ã¾ã™ã?
329 *
330 * @return サーãƒã?
331 */
332 // protected String getHost() { return host; }
333
334 /**
335 * ユーザーåã‚’å–å¾—ã—ã¾ã™ã?
336 *
337 * @return ユーザー
338 */
339 // protected String getUser() { return user; }
340
341 /**
342 * パスワードをå–å¾—ã—ã¾ã™ã?
343 *
344 * @return パスワー�
345 */
346 // protected String getPassword() { return passwd; }
347
348 /**
349 * 接続ã«åˆ©ç”¨ã™ã‚‹ãƒã?ト番å·ã‚’è¨å®šã—ã¾ã™ã?
350 *
351 * @param port 接続ã«åˆ©ç”¨ã™ã‚‹ãƒã?ト番å·
352 */
353 @Override
354 public void setPort( final String port ) {
355 if( port != null ) {
356 this.port = port ;
357 }
358 }
359
360 /**
361 * ãƒã?トをå–å¾—ã—ã¾ã™ã?
362 * è¨å®šã•れã¦ã?‚‹ç”Ÿã?port属æ?(nullã‚‚ã‚りã†ã‚?ã‚’è¿”ã—ã¾ã™ã?
363 *
364 * @return ãƒã?ãƒ?
365 */
366 protected String getPort() { return port; }
367
368 /**
369 * ãƒã?トをå–å¾—ã—ã¾ã™ã?
370 * è¨å®šã•れã¦ã?‚‹port属æ?ãŒã?nullã®å ´åˆã?ã€defPortã‚’è¿”ã—ã¾ã™ã?
371 *
372 * @param defPort port ã?null ã®å ´åˆã?åˆæœŸå€¤
373 *
374 * @return ãƒã?ãƒ?
375 */
376 protected int getPort( final int defPort) {
377 return ( port == null ) ? defPort : Integer.parseInt( port );
378 }
379
380 /**
381 * ãれãžã‚Œã®å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:true:作æ?ã™ã‚‹)ã€?
382 *
383 * -mkdirs=[true/false] ã¯ã€å—ã‘å?ã®ãƒ•ァイル(GETæ™?LOCALã€PUTæ™?サーãƒã?)ã«å–り込ã‚?ƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã?
384 * å˜åœ¨ã—ãªã??åˆã«ã€ä½œæ?ã™ã‚‹ã‹ã©ã?‹ã‚’指定ã—ã¾ã?åˆæœŸå€¤:true)
385 * 通常ã€ã‚µãƒ¼ãƒã?ã«ã€ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ã¦PUTã™ã‚‹å ´åˆã?å‹•çš„ã«ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ãŸã?‚±ãƒ¼ã‚¹ã§ä¾¿åˆ©ã§ã™ã?
386 * é€?«ã€ãƒ•ォルãƒ??確定ã—ã¦ãŠã‚Šã€æŒ‡å®šãƒ•ォルãƒ?»¥å¤–ã« PUT ã™ã‚‹ã®ã¯ãƒã‚°ã£ã¦ã?‚‹ã¨äº‹ãŒåˆ?‹ã£ã¦ã?‚‹å ´åˆã«ã¯
387 * false ã«è¨å®šã—ã¦ã€å˜åœ¨ã—ãªã?ƒ•ォルãƒ?«PUT ã—よã?¨ã™ã‚‹ã¨ã€ã‚¨ãƒ©ãƒ¼ã«ãªã‚‹ã‚ˆã?«ã—ã¾ã™ã?
388 *
389 * @param isMkdirs å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ã€‚true:作æ?ã™ã‚‹
390 */
391 @Override
392 public void setMkdirs( final boolean isMkdirs ) {
393 this.isMkdirs = isMkdirs ;
394 }
395
396 /**
397 * å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ã‚’å–å¾—ã—ã¾ã™ã?
398 *
399 * @return å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹ã€‚true:作æ?ã™ã‚‹
400 */
401 // protected boolean isMkdirs() { return isMkdirs; }
402
403 /**
404 * タイãƒ?‚¢ã‚¦ãƒˆã‚’ç§’ã§æŒ?®šã—ã¾ã?åˆæœŸå€¤:600 [ç§’])ã€?
405 *
406 * オリジナル㮠FTPClient#setDataTimeout( int ) ã¯ã€ãƒŸãƒªç§’ã§ã‚»ãƒ?ƒˆ
407 * ã—ã¾ã™ãŒã€ã“ã“ã?メソãƒ?ƒ‰ã§ã¯ã€ç§’ã§ã‚»ãƒ?ƒˆã—ã¾ã™ã?
408 *
409 * @param timeout タイãƒ?‚¢ã‚¦ãƒ?ç§’]
410 * @throws RuntimeException タイãƒ?‚¢ã‚¦ãƒˆã?æŒ?®šãŒå¤§ãã™ãŽãŸå ´å?
411 */
412 @Override
413 public void setTimeout( final int timeout ) {
414 if( Integer.MAX_VALUE / 1000 < timeout ) {
415 errAppend( "タイãƒ?‚¢ã‚¦ãƒˆã?æŒ?®šãŒå¤§ãã™ãŽã¾ã™ã?" );
416 errAppend( " timeout = [" , timeout , "]" );
417 throw new RuntimeException( getErrMsg() );
418 }
419
420 this.timeout = timeout ;
421 }
422
423 /**
424 *æŒ?®šã•れãŸã‚¿ã‚¤ãƒ?‚¢ã‚¦ãƒˆã‚’ç§’ã§å–å¾—ã—ã¾ã?åˆæœŸå€¤:600 [ç§’])ã€?
425 *
426 * @return タイãƒ?‚¢ã‚¦ãƒ?ç§’]
427 */
428 // protected int getTimeout() { return timeout; }
429
430 /**
431 * 実行状æ³ã?表示å¯å¦ ã‚’è¨å®šã—ã¾ã?åˆæœŸå€¤:false:表示ã—ãªã?ã€?
432 *
433 * @param isDisplay 実行状æ³ã?表示å¯å¦
434 */
435 @Override
436 public void setDisplay( final boolean isDisplay ) {
437 this.isDisplay = isDisplay ;
438 }
439
440 /**
441 * 実行状æ³ã?表示å¯å¦ã‚’å–å¾—ã—ã¾ã™ã?
442 *
443 * @return 実行状æ³ã?表示å¯å¦
444 */
445 // protected boolean isDisplay() { return isDisplay; }
446
447 /**
448 * ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦ ã‚’è¨å®šã—ã¾ã?åˆæœŸå€¤:false:表示ã—ãªã?ã€?
449 *
450 * @param isDebug ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦
451 */
452 @Override
453 public void setDebug( final boolean isDebug ) {
454 this.isDebug = isDebug ;
455 }
456
457 /**
458 * ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦ ã‚’å–å¾—ã—ã¾ã™ã?
459 *
460 * @return ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºå¯å¦
461 */
462 // protected boolean isDebug() { return isDebug; }
463
464 /**
465 * 処ç?¸ã«ç™ºç”Ÿã—ãŸã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
466 *
467 * @param msg メãƒ?‚»ãƒ¼ã‚¸åŒ–ã—ãŸã„オブジェクãƒ?
468 */
469 protected void errAppend( final Object msg ) {
470 errMsg.append( String.valueOf(msg) ).append( CR );
471 }
472
473 /**
474 * 処ç?¸ã«ç™ºç”Ÿã—ãŸã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã?
475 *
476 * @param msgs Object...
477 */
478 protected void errAppend( final Object... msgs ) {
479 for( int i=0; i<msgs.length; i++ ) {
480 errMsg.append( String.valueOf(msgs[i]) );
481 }
482
483 errMsg.append( CR );
484 }
485
486 /**
487 * 処ç?¸ã«ç™ºç”Ÿã—ãŸã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’å–りå?ã—ã¾ã™ã?
488 *
489 * @return エラーメãƒ?‚»ãƒ¼ã‚¸
490 */
491 @Override
492 public String getErrMsg() {
493 return errMsg.toString();
494 }
495 }