Source code: com/yaftp/ftp/FtpSessionOs.java
1 /**
2 *
3 * CopyRights Jean-Yves MENGANT 1999,2000,2001,2002
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 package com.yaftp.ftp ;
20
21 import java.util.* ;
22 import java.io.* ;
23
24 /**
25
26 Define FtpClient and Server OSes IdioSyncrasy
27
28 @Author Jean-Yves MENGANT
29 @version : 0.0.1
30
31 */
32
33 public class FtpSessionOs {
34
35 private FtpOs _curOs ;
36 private String _osDetails ;
37
38 // Constructor based on FTP SYST string
39 public FtpSessionOs ( String ftpSyst )
40 {
41 if ( ftpSyst != null )
42 {
43 _osDetails = ftpSyst ;
44 // Since UNIX may be present somewhere inside the MVS
45 // system presentation better to test it first (PB starting V2R10)
46 if ( ftpSyst.indexOf( "MVS",0 ) != -1 )
47 _curOs = new MVSftp() ;
48 else if ( ftpSyst.indexOf( "UNIX",0 ) != -1 )
49 _curOs = new UNIXftp() ;
50 else if ( ftpSyst.indexOf( "Windows",0 ) != -1 )
51 _curOs = new WINDOWSftp() ;
52 else
53 // if cannot Guess assume UNIX FTP SERVER
54 _curOs = new UNIXftp() ;
55 }
56 }
57
58 // Returns true if os is UNIX
59 public final boolean isUNIX()
60 { return ( _curOs instanceof UNIXftp ) ; }
61 // Returns true if os is MVS
62 public final boolean isMVS()
63 { return ( _curOs instanceof MVSftp ) ; }
64
65 public final void set_jesMode( boolean jesMode )
66 {
67 if ( _curOs instanceof MVSftp )
68 ((MVSftp)_curOs).set_jesMode(jesMode) ;
69 }
70
71 public final String toString()
72 { return _curOs.toString() ; }
73
74 public final String[] get_Column_Names()
75 { return _curOs.get_Column_Names() ; }
76
77 public final String getOsDetails()
78 { return _osDetails ; }
79
80 public final String getCurDirectory()
81 {
82 if ( _curOs.getCurDirectory() == null )
83 return null ;
84 else
85 return new String(_curOs.getCurDirectory()) ;
86 }
87
88 public final String getCurFile()
89 { return new String(_curOs.getCurFile()) ; }
90
91 public final Vector ftpList( FtpClientSession sess )
92 throws ClientFtpError
93 {
94 _curOs.reset_COLTITLE() ;
95 return _curOs.ftpList(sess) ;
96 }
97
98 public final void convertDirectory( String dirName )
99 { _curOs.convertDirectory( dirName ) ; }
100
101 public final void convertFileName( String fileName )
102 { _curOs.convertFileName( fileName ) ; }
103
104 public final void parseFileName( String inFile )
105 { _curOs.parseFileName( inFile ) ; }
106
107 public final String checkCurDirectory( String message )
108 { return _curOs.checkCurDirectory( message ) ; }
109
110 public final boolean hasDirChanged()
111 { return _curOs.hasDirChanged() ; }
112
113 // LOCAL class tester MVS|UNIX Directory File
114 public static void main ( String arg[] )
115 {
116 try {
117
118 FtpSessionOs curSess = new FtpSessionOs(arg[0]) ;
119
120 System.out.println( " MVS : " + curSess.isMVS() ) ;
121 System.out.println( " UNIX : " + curSess.isUNIX() ) ;
122
123 try {
124 BufferedReader in = new BufferedReader (
125 new FileReader( arg[1] )
126 ) ;
127 String s = new String() ;
128
129 while ( (s=in.readLine())!= null )
130 System.out.println(curSess._curOs.convertLISTelement(s)) ;
131
132 in.close() ;
133 } catch ( IOException e ) {
134 System.out.println( "file read Error : " + e.getMessage() ) ;
135 }
136
137 curSess.convertDirectory(arg[2]) ;
138 System.out.println( " DIR : " + curSess.getCurDirectory() ) ;
139
140 curSess.convertFileName(arg[3]) ;
141 System.out.println( " FILE : " + curSess.getCurFile() ) ;
142
143 } catch ( ClientFtpError e ) {
144 System.out.println( "Severe Error : " + e.getMessage() ) ;
145 }
146
147 }
148
149
150 }
151
152
153