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.FileInputStream;
019    import java.io.FileOutputStream;
020    import java.io.InputStream;
021    import java.io.OutputStream;
022    import java.io.BufferedInputStream;
023    import java.io.BufferedOutputStream;
024    import java.io.IOException;
025    import java.util.Map;
026    import java.util.LinkedHashMap ;
027    import java.net.MalformedURLException ;
028    
029    import jcifs.smb.SmbFile;
030    
031    /**
032     * SMBConnect.java ã¯ã€å?通的ã«ä½¿ç”¨ã•れã‚?Smb関連ã®åŸºæœ¬æ©Ÿè?を実è£?—ãŸã?クラスã§ã™ã?
033     *
034     * ã“れã¯ã€jcifs.smb パッケージをã?ースã«é–‹ç™ºã•れã¦ã?¾ã™ã?
035     * ã“ã?クラスã®å®Ÿè¡Œã«ã¯ã€jcifs-1.3.14.jar ãŒå¿?¦ã§ã™ã?
036     *
037     * 接続å?ã®URL schemeã¯ã€ä»¥ä¸‹ã?å½¢å¼ã‚’ã—ã¦ã?¾ã™ã?
038     *     smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value[param2=value2[...]]]
039     * ã“ã?URLã¯ã€å?部çš?«è‡ªå‹•作æ?ã—ã¾ã™ã?/[[share/[dir/]file]] 部åˆ?Œã€remoteFile ã¨ã—ã¦æŒ?®šã™ã‚‹éƒ¨åˆ?«ãªã‚Šã¾ã™ã? *
040     *
041     * -host=Smbサーãƒã? -user=ユーザー -passwd=パスワーãƒ?-remoteFile=Smbå…ˆã?ファイルå?ã‚’å¿??設定ã—ã¾ã™ã?
042     * -localFile=ローカルã®ãƒ•ァイルåã?ã€å¿??ã§ã¯ã‚りã¾ã›ã‚“ãŒã?-command=DEL ã®å ´åˆã«ã®ã¿ä¸è¦ã§ã‚りã€?
043     * ãれ以外ã? command ã®å ´åˆã?ã€å¿?¦ã§ã™ã?
044     *
045     * -command=[GET/PUT/DEL/GETDIR/PUTDIR/DELDIR] ã¯ã€SFTPサーãƒã?ã«å¯¾ã—ã¦ã®å‡¦ç??方法をæŒ?®šã—ã¾ã™ã?
046     *   GET:Smbサーãƒã?ã‹ã‚‰ãƒ­ãƒ¼ã‚«ãƒ«ã«ãƒ•ァイル転é€ã—ã¾ã?åˆæœŸå€¤)
047     *   PUT:ローカルファイルをSmbサーãƒã?ã« PUT(STOREã€SAVEã€UPLOADã€ãªã©ã¨åŒæ„èª?ã—ã¾ã™ã?
048     *   DEL:Smbサーãƒã?ã®æŒ?®šã?ファイルを削除ã—ã¾ã™ã?ã“ã?å ´åˆã?ã¿ã€?localFile 属æ?ã®æŒ?®šã?ä¸è¦ã§ã™ã?
049     *   GETDIR,PUTDIR,DELDIR:æŒ?®šã?フォルãƒ?»¥ä¸‹ã?ファイルをå?ç?—ã¾ã™ã?
050     *
051     * -mkdirs=[true/false] ã¯ã€å—ã‘å?ã®ãƒ•ァイル(GETæ™?LOCALã€PUTæ™?Smbサーãƒã?)ã«å–り込ã‚?ƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã?
052     * 存在ã—ãªã??åˆã«ã€ä½œæ?ã™ã‚‹ã‹ã©ã?‹ã‚’指定ã—ã¾ã?åˆæœŸå€¤:true)ã€?
053     * 通常ã€Smbサーãƒã?ã«ã€ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ã¦PUTã™ã‚‹å ´åˆã?å‹•çš„ã«ãƒ•ォルãƒ?šŽå±¤ã‚’作æ?ã—ãŸã?‚±ãƒ¼ã‚¹ã§ä¾¿åˆ©ã§ã™ã?
054     * é€?«ã€ãƒ•ォルãƒ??確定ã—ã¦ãŠã‚Šã€æŒ‡å®šãƒ•ォルãƒ?»¥å¤–ã« PUT ã™ã‚‹ã®ã¯ãƒã‚°ã£ã¦ã?‚‹ã¨äº‹ãŒåˆ?‹ã£ã¦ã?‚‹å ´åˆã«ã¯
055     * false ã«è¨­å®šã—ã¦ã€å­˜åœ¨ã—ãªã?ƒ•ォルãƒ?«PUT ã—よã?¨ã™ã‚‹ã¨ã€ã‚¨ãƒ©ãƒ¼ã«ãªã‚‹ã‚ˆã?«ã—ã¾ã™ã?
056     *
057     * 引数æ–?­—å?中ã«ç©ºç™½ã‚’å«ã‚??åˆã?ã€ãƒ€ãƒ–ルコーãƒ??ション("") ã§æ‹¬ã£ã¦ä¸‹ã•ã??
058     * 引数æ–?­—å?ã® ã€?ã€ã?å‰å¾Œã«ã¯ã€ç©ºç™½ã¯æŒŸã‚ã¾ã›ã‚“。å¿?šã€?key=value ã®æ§˜ã«
059     * 繋ã’ã¦ãã ã•ã„ã€?
060     *
061     * @og.formSample
062     *  SMBConnect -host=Smbサーãƒã? -user=ユーザー -passwd=パスワーãƒ?-remoteFile=Smbå…ˆã?ファイルå?[-localFile=ローカルã®ãƒ•ァイルå]
063     *                   [-command=[GET/PUT/DEL/GETDIR/PUTDIR/DELDIR] ] ]
064     *
065     *    -host=Smbサーãƒã?                 ?šæŽ¥ç¶šå?ã®Smbサーãƒã?ã®ã‚¢ãƒ‰ãƒ¬ã‚¹ã¾ãŸã?ã€ã‚µãƒ¼ãƒã?å?
066     *    -user=ユーザー                    ?šæŽ¥ç¶šã™ã‚‹ãƒ¦ãƒ¼ã‚¶ãƒ¼å?
067     *    -passwd=パスワーãƒ?               ?šæŽ¥ç¶šã™ã‚‹ãƒ¦ãƒ¼ã‚¶ãƒ¼ã®ãƒ‘スワーãƒ?
068     *    -remoteFile=Smbå…ˆã?ファイルå?    ?šæŽ¥ç¶šå?ã®Smbサーãƒã?å´ã®ãƒ•ァイルåã?PUT,GET 関係ãªãSmbå´ã¨ã—ã¦æŒ?®šã—ã¾ã™ã?
069     *   [-localFile=ローカルã®ãƒ•ァイルå]  ?šãƒ­ãƒ¼ã‚«ãƒ«ã®ãƒ•ァイルåã?PUT,GET 関係ãªãローカルファイルを指定ã—ã¾ã™ã?
070     *   [-domain=ドメイン ]                ?šæŽ¥ç¶šã™ã‚‹ã‚µãƒ¼ãƒã?ã®ãƒ‰ãƒ¡ã‚¤ãƒ³ã‚’指定ã—ã¾ã™ã?
071     *   [-port=ãƒã?ãƒ?]                    ?šæŽ¥ç¶šã™ã‚‹ã‚µãƒ¼ãƒã?ã®ãƒã?トをæŒ?®šã—ã¾ã™ã?
072     *   [-command=[GET/PUT/DEL] ]          ?šSmbサーãƒã?å´ã§ã®å‡¦ç??方法をæŒ?®šã—ã¾ã™ã?
073     *             [GETDIR/PUTDIR/DELDIR]]          GET:Smb⇒LOCALã€PUT:LOCAL⇒Smb ã¸ã®è»¢é€ã§ã?åˆæœŸå€¤:GET)
074     *                                              DEL:Smbファイルを削除ã—ã¾ã™ã?
075     *                                              GETDIR,PUTDIR,DELDIR æŒ?®šã?フォルãƒ?»¥ä¸‹ã?ファイルをå?ç?—ã¾ã™ã?
076     *   [-mkdirs=[true/false]  ]           ?šå—ã‘å?ファイル(GETæ™?LOCALã€PUTæ™?Smbサーãƒã?)ã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:true)
077     *                                              (false:ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªãŒç„¡ã‘れã°ã€ã‚¨ãƒ©ãƒ¼ã«ã—ã¾ã™ã?)
078     *   [-display=[false/true] ]           ?štrueã¯ã€æ¤œç´¢çжæ³ã‚’表示ã—ã¾ã?åˆæœŸå€¤:false)
079     *   [-debug=[false|true]   ]           ?šãƒ‡ãƒãƒƒã‚°æƒ??を標準å?力ã«è¡¨ç¤ºã™ã‚‹(true)ã‹ã—ãªã?false)ã?åˆæœŸå€¤:false[表示ã—ãªã„])
080     *
081     * @og.rev 5.1.6.0 (2010/05/01) æ–°è¦è¿½åŠ?
082     *
083     * @version  5.0
084     * @author       Kazuhiko Hasegawa
085     * @since    JDK5.0,
086     */
087    public final class SMBConnect extends AbstractConnect {
088            private String  domain          = null;                 // ドメイン
089            private String  connURI         = null;                 // Smb接続ã™ã‚‹å?åˆã?URIæ–?­—å?(ã®å…ˆé?)
090    
091            /**
092             * ãƒ?ƒ•ォルトコンストラクター
093             */
094    //      public SMBConnect() {
095    //      }
096    
097            /**
098             * Smbサーãƒã?ã¸ã®æŽ¥ç¶šã?ログインを行ã„ã¾ã™ã?
099             *
100             * ã“ã?メソãƒ?ƒ‰ã¯ã€å?期化メソãƒ?ƒ‰ã§ã™ã?
101             * Smbサーãƒã?ã¸ã®æŽ¥ç¶šã?ログインを行ã„ã¾ã™ã?ã§ã€è¤?•°ãƒ•ァイルを転é€ã™ã‚?
102             * ケースã§ã¯ã€æœ€åˆã«?‘度ã?‘呼ã³å‡ºã™ã ã‘ã§ã™ã?
103             * 接続å?を変更ã™ã‚‹å ´åˆã?ã€ã‚‚ã?¸?º¦ã“ã?メソãƒ?ƒ‰ã‚’コールã™ã‚‹å¿?¦ãŒã‚りã¾ã™ã?
104             * (ãã?よã†ãªå ´åˆã?ã€??常ã€ã‚ªãƒ–ジェクトを構築ã—ãªãŠã™æ–¹ãŒã‚ˆã?¨æ€ã„ã¾ã™ã?)
105             * 接続時ã®ã‚¢ãƒ‰ãƒ¬ã‚¹ã¯ã€ä¸‹è¨˜ã?å½¢å¼ã«ãªã‚Šã¾ã™ãŒã€ãƒ•ァイルåã?ç®?‰€ã¯ã€action æ™‚ã«æŒ?®šã™ã‚‹ãŸã‚ã?
106             * ã“ã“ã§ã¯ã€å?頭部åˆ?‚’å…ˆã«ç”¨æ„ã—ã¦ãŠãã¾ã™ã?
107             *     smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value[param2=value2[...]]]
108             *
109             */
110            @Override
111            public void connect() {
112                    if( isDisplay ) { System.out.println( "CONNECT: HOST=" + host + ",USER=" + user + ",PORT=" + port ); }
113    
114                    if( host == null ) {
115                            errAppend( "host ã¯ã€å¿??ã§ã™ã?" );
116                            throw new RuntimeException( getErrMsg() );
117                    }
118    
119                    // smb://[[[domain;]username[:password]@]server[:port] ã“ã“ã¾ã§ä½œæ?
120                    connURI = "smb://"
121                                    + ((domain == null) ? "" : domain + ";" )
122                                    + ((user   == null) ? "" : user )
123                                    + ((passwd   == null) ? "" : ":" + passwd )
124                                    + ((user   == null) ? "" : "@" )
125                                    + host
126                                    + ((port   == null) ? "" : ":" + port ) ;
127    
128                    if( isDebug ) { System.out.println( "connURI=" + connURI ); }
129            }
130    
131            /**
132             * Smbサーãƒã?ã¨ã®æŽ¥ç¶šã‚’クローズã—ã¾ã™ã?
133             *
134             * ã“ã“ã§ã¯ã€ä½•も処ç?‚’行ã„ã¾ã›ã‚“ã€?
135             *
136             */
137            @Override
138            public void disconnect() {
139                    if( isDisplay ) { System.out.println( "DISCONNECT:" ); }
140            }
141    
142            /**
143             * command="GET" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
144             *
145             * 接続å?ã®Smbサーãƒã?å´ã®ãƒ•ァイルåをローカルã«ãƒ?‚¦ãƒ³ãƒ­ãƒ¼ãƒ‰ã—ã¾ã™ã?
146             *
147             * @param       localFile       ローカルã®ãƒ•ァイルå?
148             * @param       remoteFile      Smbå…ˆã?ファイルå?
149             * @throws IOException 入出力エラーãŒç™ºç”Ÿã—ãŸã¨ã?
150             */
151            @Override
152            protected void actionGET( final String localFile, final String remoteFile ) throws IOException {
153                    if( isDebug ) { System.out.println( "GET: " + remoteFile + " => " + localFile ); }
154    
155                    SmbFile rmtFile = makeSmbURI( remoteFile );
156    
157                    // GET(DOWNLOAD)å–得時ã¯ã€ãƒ­ãƒ¼ã‚«ãƒ«ãƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹å¿?¦ãŒã‚ã‚‹ã€?
158                    if( isMkdirs ) {
159                            makeLocalDir( localFile );
160                    }
161    
162                    InputStream     input  = null;
163                    OutputStream    output = null;
164                    try {
165    //                      input  = new BufferedInputStream( new SmbFileInputStream( remoteFile ) );
166                            input  = new BufferedInputStream( rmtFile.getInputStream() );
167                            output = new FileOutputStream( localFile );
168                            FileUtil.copy( input,output );
169                    }
170                    finally {
171                            Closer.ioClose( input );
172                            Closer.ioClose( output );
173                    }
174            }
175    
176            /**
177             * command="GETDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
178             *
179             * 接続å?ã®Smbサーãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªä»¥ä¸‹ã‚’ローカルãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«éšŽå±¤æ§‹é?ã®ã¾ã¾ãƒ?‚¦ãƒ³ãƒ­ãƒ¼ãƒ‰ã—ã¾ã™ã?
180             *
181             * @param       localDir        ローカルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
182             * @param       remoteDir       Smbå…ˆã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
183             * @throws IOException 入出力エラーãŒç™ºç”Ÿã—ãŸã¨ã?
184             */
185            @Override
186            protected void actionGETdir( final String localDir, final String remoteDir ) throws IOException {
187                    SmbFile rmtFile = makeSmbURI( remoteDir );
188    
189                    SmbFile[] rmtFiles = rmtFile.listFiles();
190                    for( int i=0; i<rmtFiles.length; i++ ) {
191                            String rmt = rmtFiles[i].getName();
192                            if( rmtFiles[i].isDirectory() ) {
193                                    actionGETdir( addFile( localDir,rmt ),addFile( remoteDir,rmt ) );
194                            }
195                            else {
196                                    actionGET( addFile( localDir,rmt ),addFile( remoteDir,rmt ) );
197                            }
198                    }
199            }
200    
201            /**
202             * command="PUT" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
203             *
204             * ローカルファイルをã?接続å?ã®Smbサーãƒã?å´ã«ã‚¢ãƒ??ロードã—ã¾ã™ã?
205             *
206             * @param       localFile       ローカルã®ãƒ•ァイルå?
207             * @param       remoteFile      Smbå…ˆã?ファイルå?
208             * @throws IOException 入出力エラーãŒç™ºç”Ÿã—ãŸã¨ã?
209             */
210            @Override
211            protected void actionPUT( final String localFile, final String remoteFile ) throws IOException {
212                    if( isDebug ) { System.out.println( "PUT: " + localFile + " => " + remoteFile ); }
213    
214                    SmbFile rmtFile = makeSmbURI( remoteFile );
215    
216                    // 存在ãƒã‚§ãƒ?‚¯?šã™ã§ã«å­˜åœ¨ã—ã¦ã?‚‹å ´åˆã?ã€å?ã«å‰Šé™¤ã—ã¾ã™ã?
217                    if( rmtFile.exists() ) { rmtFile.delete() ; }
218                    else {
219                            // PUT(UPLOAD)登録時ã?ã€ãƒªãƒ¢ãƒ¼ãƒˆãƒ•ァイルã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹å¿?¦ãŒã‚ã‚‹ã€?
220                            if( isMkdirs ) {
221                                    String tmp = rmtFile.getParent();
222                                    SmbFile dir = new SmbFile( tmp );
223                                    if( !dir.exists() ) { dir.mkdirs() ; }
224                            }
225                    }
226    
227                    InputStream     input  = null;
228                    OutputStream    output = null;
229                    try {
230                            input  = new FileInputStream( localFile );
231    //                      output = new BufferedOutputStream( new SmbFileOutputStream( remoteFile ) );
232                            output = new BufferedOutputStream( rmtFile.getOutputStream() );
233    
234                            FileUtil.copy( input,output );
235                    }
236                    finally {
237                            Closer.ioClose( input );
238                            Closer.ioClose( output );
239                    }
240            }
241    
242            /**
243             * command="DEL" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
244             *
245             * 接続å?ã®Smbサーãƒã?å´ã®ãƒ•ァイルåを削除ã—ã¾ã™ã?
246             *
247             * @param       remoteFile      Smbå…ˆã?ファイルå?
248             * @throws IOException 入出力エラーãŒç™ºç”Ÿã—ãŸã¨ã?
249             */
250            @Override
251            protected void actionDEL( final String remoteFile ) throws IOException {
252                    if( isDebug ) { System.out.println( "DEL: " + remoteFile ); }
253    
254                    SmbFile rmtFile = makeSmbURI( remoteFile );
255                    rmtFile.delete() ;
256            }
257    
258            /**
259             * command="DELDIR" ãŒæŒ‡å®šã•れãŸã¨ãã?処ç?‚’行ã„ã¾ã™ã?
260             *
261             * 接続å?ã®Smbサーãƒã?å´ã®ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªä»¥ä¸‹ã‚’ローカルãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã«éšŽå±¤æ§‹é?ã®ã¾ã¾ãƒ?‚¦ãƒ³ãƒ­ãƒ¼ãƒ‰ã—ã¾ã™ã?
262             *
263             * @param       remoteDir       Smbå…ˆã?ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªå?
264             * @throws IOException 入出力エラーãŒç™ºç”Ÿã—ãŸã¨ã?
265             */
266            @Override
267            protected void actionDELdir( final String remoteDir ) throws IOException {
268                    SmbFile rmtFile = makeSmbURI( remoteDir );
269                    SmbFile[] rmtFiles = rmtFile.listFiles();
270                    for( int i=0; i<rmtFiles.length; i++ ) {
271                            String rmt = addFile( remoteDir,rmtFiles[i].getName() );
272                            if( rmtFiles[i].isDirectory() ) {
273                                    actionDELdir( rmt );
274                            }
275                            else {
276                                    actionDEL( rmt );
277    //                              rmtFiles[i].delete();
278                            }
279                    }
280                    rmtFile.delete();
281            }
282    
283            /**
284             * SMBå½¢å¼ã?URLを作æ?ã—ã¾ã™ã?
285             *
286             * 処ç?š„ã«ã¯ã€å?部ã§å…ˆã«ä½œæ?済ã¿ã® connURI ã¨ã€å¼•æ•°ã®ãƒ•ァイルパスを文字å?連çµã—ã¾ã™ã?
287             * connURI ã®æœ?¾Œã«ã¯ã€?/" を付加ã—ã¦ã?¾ã›ã‚“ã®ã§ã€å¼•æ•°ã®ãƒ•ァイルパスã«ã€?
288             * "/" ã‚’å«ã¾ãªã??åˆã?ã€?/" を付加ã—ã¾ã™ã?
289             *
290             *     smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]]
291             *
292             * @param       remoteFile      Smbå…ˆã?ファイルå?
293             *
294             * @return      SMBå½¢å¼ã?URL
295             */
296            private SmbFile makeSmbURI( final String remoteFile ) throws MalformedURLException {
297                    final String smbFile ;
298    
299                    if( remoteFile.startsWith( "smb://" ) ) {
300                            smbFile = remoteFile;
301                    }
302                    else if( remoteFile.startsWith( "/" ) ) {
303                            smbFile = connURI + remoteFile ;
304                    }
305                    else {
306                            smbFile = connURI + "/" + remoteFile ;
307                    }
308    
309    //              SmbFile rmtFile = new SmbFile( smbFile );
310    //              return rmtFile;
311                    return new SmbFile( smbFile );
312            }
313    
314            /**
315             * 接続å?ã«ãƒ­ã‚°ã‚¤ãƒ³ã™ã‚‹ãƒ‰ãƒ¡ã‚¤ãƒ³ã‚’設定ã—ã¾ã™ã?
316             *
317             * @param       domain  接続å?ã«ãƒ­ã‚°ã‚¤ãƒ³ã™ã‚‹ãƒ‰ãƒ¡ã‚¤ãƒ³
318             */
319            public void setDomain( final String domain ) {
320                    this.domain = domain ;
321            }
322    
323    // ******************************************************************************************************* //
324    //       以下ã?å˜ç‹¬ã§ä½¿ç”¨ã™ã‚‹å ´åˆã? main処ç?
325    // ******************************************************************************************************* //
326    
327            private static final Map<String,String> mustProparty   ;          // ?»ãƒ—ロパティ?½å¿??ãƒã‚§ãƒ?‚¯ç”¨ Map
328            private static final Map<String,String> usableProparty ;          // ?»ãƒ—ロパティ?½æ•´åˆæ?ãƒã‚§ãƒ?‚¯ Map
329    
330            static {
331                    mustProparty = new LinkedHashMap<String,String>();
332                    mustProparty.put( "host",               "接続å?ã®Smbサーãƒã?ã®ã‚¢ãƒ‰ãƒ¬ã‚¹ã¾ãŸã?ã€ã‚µãƒ¼ãƒã?å?å¿??)" );
333                    mustProparty.put( "user",               "接続ã™ã‚‹ãƒ¦ãƒ¼ã‚¶ãƒ¼å?å¿??)" );
334                    mustProparty.put( "passwd",             "接続ã™ã‚‹ãƒ¦ãƒ¼ã‚¶ãƒ¼ã®ãƒ‘スワーãƒ?å¿??)" );
335                    mustProparty.put( "command",    "Smbサーãƒã?å´ã§ã®å‡¦ç??æ–¹æ³?GET/PUT/DEL/GETDIR/PUTDIR/DELDIR)を指定ã—ã¾ã™ã?(å¿??)" );
336                    mustProparty.put( "remoteFile", "接続å?ã®Smbサーãƒã?å´ã®ãƒ•ァイルå?å¿??)" );
337    
338                    usableProparty = new LinkedHashMap<String,String>();
339                    usableProparty.put( "localFile",        "ローカルã®ãƒ•ァイルå? );
340                    usableProparty.put( "domain",           "接続å?ã«ãƒ­ã‚°ã‚¤ãƒ³ã™ã‚‹ãƒ‰ãƒ¡ã‚¤ãƒ³ã‚’指定ã—ã¾ã™ã?" );
341                    usableProparty.put( "port",                     "接続ã«åˆ©ç”¨ã™ã‚‹ãƒã?ト番å·ã‚’設定ã—ã¾ã™ã?" );
342                    usableProparty.put( "mkdirs",           "å—ã‘å´ãƒ•ァイル(GETæ™?LOCALã€PUTæ™?Smbサーãƒã?)ã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹(åˆæœŸå€¤:true)" );
343                    usableProparty.put( "display",          "[false/true]:trueã¯ã€æ¤œç´¢çжæ³ã‚’表示ã—ã¾ã?åˆæœŸå€¤:false)" );
344                    usableProparty.put( "debug",            "ãƒ?ƒãƒ?‚°æƒ??を標準å?力ã«è¡¨ç¤ºã™ã‚‹(true)ã‹ã—ãªã?false)ã? +
345                                                                                            CR + "(åˆæœŸå€¤:false:表示ã—ãªã?" );
346            }
347    
348            private static final String[] CMD_LST  = new String[] { "GET","PUT","DEL","GETDIR","PUTDIR","DELDIR" };
349    
350            /**
351             * ã“ã?クラスã®å‹•作確èªç”¨ã®ã€main メソãƒ?ƒ‰ã§ã™ã?
352             *
353             * @param       args    コマンド引数é…å?
354             */
355            public static void main( final String[] args ) {
356                    Argument arg = new Argument( "org.opengion.fukurou.util.SMBConnect" );
357                    arg.setMustProparty( mustProparty );
358                    arg.setUsableProparty( usableProparty );
359                    arg.setArgument( args );
360    
361                    SMBConnect smb = new SMBConnect();
362    
363                    String host   = arg.getProparty( "host");                       // Smbサーãƒã?
364                    String user   = arg.getProparty( "user" );                      // ユーザー
365                    String passwd = arg.getProparty( "passwd" );            // パスワー�
366    
367                    smb.setHostUserPass( host,user,passwd );
368    
369                    smb.setDomain(  arg.getProparty( "domain"       ) );                                    // 接続å?ã«ãƒ­ã‚°ã‚¤ãƒ³ã™ã‚‹ãƒ‰ãƒ¡ã‚¤ãƒ³ã‚’指定ã—ã¾ã™ã?
370                    smb.setPort(    arg.getProparty( "port"         ) );                                    // 接続ã«åˆ©ç”¨ã™ã‚‹ãƒã?ト番å·ã‚’設定ã—ã¾ã™ã?
371                    smb.setMkdirs(  arg.getProparty( "mkdirs"       ,true           ) );            // å—ã‘å´ãƒ•ァイルã«ãƒ?‚£ãƒ¬ã‚¯ãƒˆãƒªã‚’作æ?ã™ã‚‹ã‹ã©ã?‹
372                    smb.setDisplay( arg.getProparty( "display"      ,false          ) );            // trueã¯ã€æ¤œç´¢çжæ³ã‚’表示ã—ã¾ã?åˆæœŸå€¤:false)
373                    smb.setDebug(   arg.getProparty( "debug"        ,false          ) );            // ãƒ?ƒãƒ?‚°æƒ??を標準å?力ã«è¡¨ç¤ºã™ã‚‹(true)ã‹ã—ãªã?false)ã?
374    
375                    try {
376                            // コãƒã‚¯ãƒˆã—ã¾ã™ã?
377                            smb.connect();
378    
379                            String command          = arg.getProparty( "command" ,"GET" ,CMD_LST  );        // Smb処ç??方法をæŒ?®šã—ã¾ã™ã?
380                            String localFile        = arg.getProparty( "localFile"  );                                      // ローカルã®ãƒ•ァイルå?
381                            String remoteFile       = arg.getProparty( "remoteFile" );                                      // Smbå…ˆã?ファイルå?
382    
383                            // command , localFile , remoteFile ã‚’å?ã«ã€SFTP処ç?‚’行ã„ã¾ã™ã?
384                            smb.action( command,localFile,remoteFile );
385                    }
386                    catch( RuntimeException ex ) {
387                            System.err.println( smb.getErrMsg() );
388                    }
389                    finally {
390                            // ホストã¨ã®æŽ¥ç¶šã‚’終äº?—ã¾ã™ã?
391                            smb.disconnect();
392                    }
393            }
394    }