Source Code Cross Referenced for FileChannel.java in  » Net » ssh-web-proxy » com » ericdaugherty » sshwebproxy » 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 » ssh web proxy » com.ericdaugherty.sshwebproxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * $Source: /cvsroot/sshwebproxy/src/java/com/ericdaugherty/sshwebproxy/FileChannel.java,v $
003:         * $Revision: 1.2 $
004:         * $Author: edaugherty $
005:         * $Date: 2003/11/23 00:18:10 $
006:         ******************************************************************************
007:         * Copyright (c) 2003, Eric Daugherty (http://www.ericdaugherty.com)
008:         * All rights reserved.
009:         *
010:         * Redistribution and use in source and binary forms, with or without
011:         * modification, are permitted provided that the following conditions are met:
012:         *
013:         *     * Redistributions of source code must retain the above copyright notice,
014:         *       this list of conditions and the following disclaimer.
015:         *     * Redistributions in binary form must reproduce the above copyright
016:         *       notice, this list of conditions and the following disclaimer in the
017:         *       documentation and/or other materials provided with the distribution.
018:         *     * Neither the name of the Eric Daugherty nor the names of its
019:         *       contributors may be used to endorse or promote products derived
020:         *       from this software without specific prior written permission.
021:         *
022:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
023:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
024:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
025:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
026:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
027:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
028:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
029:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
030:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
031:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
032:         * THE POSSIBILITY OF SUCH DAMAGE.
033:         * *****************************************************************************
034:         * For current versions and more information, please visit:
035:         * http://www.ericdaugherty.com/dev/sshwebproxy
036:         *
037:         * or contact the author at:
038:         * web@ericdaugherty.com
039:         *****************************************************************************/package com.ericdaugherty.sshwebproxy;
040:
041:        import org.apache.commons.logging.LogFactory;
042:        import org.apache.commons.logging.Log;
043:
044:        import java.io.*;
045:        import java.util.List;
046:
047:        import com.sshtools.j2ssh.SftpClient;
048:        import com.sshtools.j2ssh.SshClient;
049:
050:        /**
051:         * Provide an implementation of the SshChannel for transfering
052:         * files over an SshConnection.
053:         *
054:         * @author Eric Daugherty
055:         */
056:        public class FileChannel extends SshChannel implements  SshConstants {
057:
058:            //***************************************************************
059:            // Variables
060:            //***************************************************************
061:
062:            /** The SftpClient */
063:            private SftpClient sftpClient;
064:
065:            /** Logger */
066:            private static final Log log = LogFactory.getLog(FileChannel.class);
067:
068:            //***************************************************************
069:            // Constructor
070:            //***************************************************************
071:
072:            /**
073:             * Opens a file transfer session with the server.
074:             *
075:             * @param sshConnection the connection to use.
076:             * @param sshClient the  SSH API client.
077:             * @throws SshConnectException thrown if there is any error opening
078:             * the connection.
079:             */
080:            public FileChannel(SshConnection sshConnection, SshClient sshClient)
081:                    throws SshConnectException {
082:                super (CHANNEL_TYPE_FILE, sshConnection);
083:
084:                try {
085:                    sftpClient = sshClient.openSftpClient();
086:                } catch (IOException ioException) {
087:                    log
088:                            .warn(
089:                                    "FileChannel constructor failed, IOException occured while setting up channel to : "
090:                                            + sshConnection.getConnectionInfo()
091:                                            + ".  Exception: " + ioException,
092:                                    ioException);
093:                    throw new SshConnectException(
094:                            "Unable to establish File Connection.  IOExeption occured: "
095:                                    + ioException);
096:                }
097:
098:                if (log.isInfoEnabled())
099:                    log.debug("New FileChannel opened to: "
100:                            + sshConnection.getConnectionInfo());
101:            }
102:
103:            //***************************************************************
104:            // SshChannel Methods
105:            //***************************************************************
106:
107:            /**
108:             * Closes the Reader and Writer after the Channel has been closed.
109:             * This should only be called by the SshConnection
110:             * class and never directly called from this class.
111:             */
112:            public void close() {
113:                // Close Readers and Writers.
114:                if (log.isInfoEnabled())
115:                    log.debug("Closing FileChannel connected to: "
116:                            + sshConnection.getConnectionInfo());
117:
118:                try {
119:                    sftpClient.quit();
120:                } catch (IOException ioException) {
121:                    log.warn("IOException while closing FileChannel: "
122:                            + ioException);
123:                }
124:            }
125:
126:            /**
127:             * Indicates whether this connection is still active.
128:             *
129:             * @return true if this connection is still active.
130:             */
131:            public boolean isConnected() {
132:                return !sftpClient.isClosed();
133:            }
134:
135:            /**
136:             * Returns the page that should be used to display this Channel.
137:             *
138:             * @return
139:             */
140:            public String getPage() {
141:                return PAGE_FILE_HOME + "?connection="
142:                        + sshConnection.getConnectionInfo() + "&channel="
143:                        + getChannelId();
144:            }
145:
146:            //***************************************************************
147:            // Public Methods
148:            //***************************************************************
149:
150:            /**
151:             * Returns the present working directory for this channel.
152:             *
153:             * @return result of pwd command.
154:             */
155:            public String getCurrentDirectory() {
156:                return sftpClient.pwd();
157:            }
158:
159:            /**
160:             * Returns a listing of the current directory.
161:             *
162:             * @return a valid list, or null if an error occured.
163:             */
164:            public List getCurrentDirectoryListing() {
165:                try {
166:                    return sftpClient.ls();
167:                } catch (IOException ioException) {
168:                    log.info("Error occured while getting directory listing: "
169:                            + ioException);
170:                    return null;
171:                }
172:            }
173:
174:            /**
175:             * Change to a different directory.
176:             *
177:             * @param directory
178:             * @return true if successful.
179:             */
180:            public boolean changeDirectory(String directory) {
181:                try {
182:                    sftpClient.cd(directory);
183:                    return true;
184:                } catch (IOException ioException) {
185:                    log.info("Error occured while changing directory listing: "
186:                            + ioException);
187:                    return false;
188:                }
189:            }
190:
191:            /**
192:             * Downloads a file from the remote server.
193:             *
194:             * @param fileName the name of the file to download.
195:             * @param outputStream the stream to write the downloaded file to.
196:             * @throws IOException thrown if there is an error reading the file.
197:             */
198:            public void downloadFile(String fileName, OutputStream outputStream)
199:                    throws IOException {
200:                sftpClient.get(fileName, outputStream);
201:            }
202:
203:            /**
204:             * Uploads a file to the remote server.
205:             *
206:             * @param fileName the file to upload.
207:             * @param inputStream the file as an InputStream.
208:             * @throws IOException thrown if there is an error writing the file.
209:             */
210:            public void uploadFile(String fileName, InputStream inputStream)
211:                    throws IOException {
212:                sftpClient.put(inputStream, fileName);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.