Source Code Cross Referenced for FTPClientTest.java in  » Net » edtftpj » com » enterprisedt » net » ftp » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » edtftpj » com.enterprisedt.net.ftp.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *
003:         *  Java FTP client library.
004:         *
005:         *  Copyright (C) 2000-2003  Enterprise Distributed Technologies Ltd
006:         *
007:         *  www.enterprisedt.com
008:         *
009:         *  This library is free software; you can redistribute it and/or
010:         *  modify it under the terms of the GNU Lesser General Public
011:         *  License as published by the Free Software Foundation; either
012:         *  version 2.1 of the License, or (at your option) any later version.
013:         *
014:         *  This library is distributed in the hope that it will be useful,
015:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017:         *  Lesser General Public License for more details.
018:         *
019:         *  You should have received a copy of the GNU Lesser General Public
020:         *  License along with this library; if not, write to the Free Software
021:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022:         *
023:         *  Bug fixes, suggestions and comments should be should posted on 
024:         *  http://www.enterprisedt.com/forums/index.php
025:         *
026:         *  Change Log:
027:         *
028:         *      $Log: FTPClientTest.java,v $
029:         *      Revision 1.7  2007-08-09 00:10:53  hans
030:         *      Removed unused imports.
031:         *
032:         *      Revision 1.6  2005/06/03 11:27:05  bruceb
033:         *      comment update
034:         *
035:         *      Revision 1.5  2004/08/31 10:45:08  bruceb
036:         *      assign args correctly
037:         *
038:         *      Revision 1.4  2004/05/01 16:56:14  bruceb
039:         *      cleaned up and deprecated
040:         *
041:         *      Revision 1.3  2002/11/19 22:00:41  bruceb
042:         *      simple test case
043:         *
044:         *
045:         */package com.enterprisedt.net.ftp.test;
046:
047:        import com.enterprisedt.net.ftp.FTPClient;
048:        import com.enterprisedt.net.ftp.FTPConnectMode;
049:        import com.enterprisedt.net.ftp.FTPException;
050:        import com.enterprisedt.net.ftp.FTPTransferType;
051:        import com.enterprisedt.util.debug.Level;
052:        import com.enterprisedt.util.debug.Logger;
053:
054:        /**
055:         *  Basic test harness. No longer in use or maintained - see the
056:         *  JUnit tests and the demo program for current tests.
057:         *
058:         *
059:         *  @author         Bruce Blackshaw
060:         *  @version        $Revision: 1.7 $
061:         *
062:         */
063:        public class FTPClientTest {
064:
065:            /**
066:             *  Revision control id
067:             */
068:            public static final String cvsId = "$Id: FTPClientTest.java,v 1.7 2007-08-09 00:10:53 hans Exp $";
069:
070:            /**
071:             *   Test harness
072:             */
073:            public static void main(String args[]) {
074:
075:                Logger.setLevel(Level.ALL);
076:
077:                // we want remote host, user name and password
078:                if (args.length < 7) {
079:                    System.out.println(args.length);
080:                    usage();
081:                    System.exit(1);
082:                }
083:                try {
084:
085:                    // assign args to make it clear
086:                    String host = args[0];
087:                    String user = args[1];
088:                    String password = args[2];
089:                    String filename = args[3];
090:                    String directory = args[4];
091:                    String mode = args[5];
092:                    String connMode = args[6];
093:
094:                    // connect and test supplying port no.
095:                    FTPClient ftp = new FTPClient();
096:                    ftp.setControlEncoding("UTF-8");
097:                    ftp.setRemoteHost(host);
098:                    ftp.setRemotePort(21);
099:                    ftp.connect();
100:                    ftp.login(user, password);
101:                    ftp.quote("LANG da-DK", new String[] { "200" });
102:                    //            ftp.dirDetails(".");
103:                    ftp.chdir("test");
104:                    ftp.quit();
105:                    if (true)
106:                        return;
107:
108:                    // connect again
109:                    ftp = new FTPClient();
110:                    ftp.setRemoteHost(host);
111:
112:                    ftp.login(user, password);
113:
114:                    ftp.dir(".", false);
115:
116:                    // binary transfer
117:                    if (mode.equalsIgnoreCase("BINARY")) {
118:                        ftp.setType(FTPTransferType.BINARY);
119:                    } else if (mode.equalsIgnoreCase("ASCII")) {
120:                        ftp.setType(FTPTransferType.ASCII);
121:                    } else {
122:                        System.out.println("Unknown transfer type: " + args[5]);
123:                        System.exit(-1);
124:                    }
125:
126:                    // PASV or active?
127:                    if (connMode.equalsIgnoreCase("PASV")) {
128:                        ftp.setConnectMode(FTPConnectMode.PASV);
129:                    } else if (connMode.equalsIgnoreCase("ACTIVE")) {
130:                        ftp.setConnectMode(FTPConnectMode.ACTIVE);
131:                    } else {
132:                        System.out.println("Unknown connect mode: " + args[6]);
133:                        System.exit(-1);
134:                    }
135:
136:                    // change dir
137:                    ftp.chdir(directory);
138:
139:                    // put a local file to remote host
140:                    ftp.put(filename, filename);
141:
142:                    // get bytes
143:                    byte[] buf = ftp.get(filename);
144:                    System.out.println("Got " + buf.length + " bytes");
145:
146:                    // append local file
147:                    try {
148:                        ftp.put(filename, filename, true);
149:                    } catch (FTPException ex) {
150:                        System.out.println("Append failed: " + ex.getMessage());
151:                    }
152:
153:                    // get bytes again - should be 2 x
154:                    buf = ftp.get(filename);
155:                    System.out.println("Got " + buf.length + " bytes");
156:
157:                    // rename
158:                    ftp.rename(filename, filename + ".new");
159:
160:                    // get a remote file - the renamed one
161:                    ftp.get(filename + ".tst", filename + ".new");
162:
163:                    // ASCII transfer
164:                    ftp.setType(FTPTransferType.ASCII);
165:
166:                    // test that list() works
167:                    String[] listing = ftp.dir(".");
168:                    for (int i = 0; i < listing.length; i++)
169:                        System.out.println(listing[i]);
170:
171:                    // test that dir() works in full mode
172:                    String[] listings = ftp.dir(".", true);
173:                    for (int i = 0; i < listings.length; i++)
174:                        System.out.println(listings[i]);
175:
176:                    // try system()
177:                    System.out.println(ftp.system());
178:
179:                    // try pwd()
180:                    System.out.println(ftp.pwd());
181:
182:                    ftp.quit();
183:                } catch (Exception ex) {
184:                    System.out.println("Caught exception: " + ex.getMessage());
185:                }
186:            }
187:
188:            /**
189:             *  Basic usage statement
190:             */
191:            public static void usage() {
192:
193:                System.out.println("Usage: ");
194:                System.out.println("com.enterprisedt.net.ftp.FTPClientTest "
195:                        + "remotehost user password filename directory "
196:                        + "(ascii|binary) (active|pasv)");
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.