Java Doc for SFTPv3Client.java in  » Net » Ganymed-SSH-2 » ch » ethz » ssh2 » 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 » Ganymed SSH 2 » ch.ethz.ssh2 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   ch.ethz.ssh2.SFTPv3Client

SFTPv3Client
public class SFTPv3Client (Code)
A SFTPv3Client represents a SFTP (protocol version 3) client connection tunnelled over a SSH-2 connection. This is a very simple (synchronous) implementation.

Basically, most methods in this class map directly to one of the packet types described in draft-ietf-secsh-filexfer-02.txt.

Note: this is experimental code.

Error handling: the methods of this class throw IOExceptions. However, unless there is catastrophic failure, exceptions of the type SFTPv3Client will be thrown (a subclass of IOException). Therefore, you can implement more verbose behavior by checking if a thrown exception if of this type. If yes, then you can cast the exception and access detailed information about the failure.

Notes about file names, directory names and paths, copy-pasted from the specs:

  • SFTP v3 represents file names as strings. File names are assumed to use the slash ('/') character as a directory separator.
  • File names starting with a slash are "absolute", and are relative to the root of the file system. Names starting with any other character are relative to the user's default directory (home directory).
  • Servers SHOULD interpret a path name component ".." as referring to the parent directory, and "." as referring to the current directory. If the server implementation limits access to certain parts of the file system, it must be extra careful in parsing file names when enforcing such restrictions. There have been numerous reported security bugs where a ".." in a path name has allowed access outside the intended area.
  • An empty path name is valid, and it refers to the user's default directory (usually the user's home directory).

If you are still not tired then please go on and read the comment for SFTPv3Client.setCharset(String) .
author:
   Christian Plattner, plattner@inf.ethz.ch
version:
   $Id: SFTPv3Client.java,v 1.9 2006/09/20 12:51:37 cplattne Exp $



Field Summary
 StringcharsetName
    
final  Connectionconn
    
final  PrintStreamdebug
    
 booleanflag_closed
    
 InputStreamis
    
 intnext_request_id
    
 OutputStreamos
    
 intprotocol_version
    
 HashMapserver_extensions
    
final  Sessionsess
    

Constructor Summary
public  SFTPv3Client(Connection conn, PrintStream debug)
     Create a SFTP v3 client.
public  SFTPv3Client(Connection conn)
     Create a SFTP v3 client.

Method Summary
public  StringcanonicalPath(String path)
     Have the server canonicalize any given path name to an absolute path. This is useful for converting path names containing ".." components or relative pathnames without a leading slash into absolute paths.
Parameters:
  path - See the SFTPv3Client comment for the class for more details.
public  voidclose()
     Close this SFTP session.
public  voidcloseFile(SFTPv3FileHandle handle)
     Close a file.
public  SFTPv3FileHandlecreateFile(String fileName)
     Create a file and open it for reading and writing. Same as SFTPv3Client.createFile(String,SFTPv3FileAttributes) createFile(fileName, null) .
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
public  SFTPv3FileHandlecreateFile(String fileName, SFTPv3FileAttributes attr)
     Create a file and open it for reading and writing. You can specify the default attributes of the file (the server may or may not respect your wishes).
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
Parameters:
  attr - may be null to use server defaults.
public  SFTPv3FileHandlecreateFileTruncate(String fileName)
     Create a file (truncate it if it already exists) and open it for reading and writing. Same as SFTPv3Client.createFileTruncate(String,SFTPv3FileAttributes) createFileTruncate(fileName, null) .
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
public  SFTPv3FileHandlecreateFileTruncate(String fileName, SFTPv3FileAttributes attr)
     reate a file (truncate it if it already exists) and open it for reading and writing. You can specify the default attributes of the file (the server may or may not respect your wishes).
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
Parameters:
  attr - may be null to use server defaults.
public  voidcreateSymlink(String src, String target)
     Create a symbolic link on the server.
public  voidfsetstat(SFTPv3FileHandle handle, SFTPv3FileAttributes attr)
     Modify the attributes of a file.
public  SFTPv3FileAttributesfstat(SFTPv3FileHandle handle)
     Retrieve the file attributes of an open file.
Parameters:
  handle - a SFTPv3FileHandle handle.
public  StringgetCharset()
     The currently used charset for filename encoding/decoding.
public  intgetProtocolVersion()
     Returns the negotiated SFTP protocol version between the client and the server.
public  Vectorls(String dirName)
     List the contents of a directory.
Parameters:
  dirName - See the SFTPv3Client comment for the class for more details.
public  SFTPv3FileAttributeslstat(String path)
     Retrieve the file attributes of a file.
public  voidmkdir(String dirName, int posixPermissions)
     Create a new directory.
Parameters:
  dirName - See the SFTPv3Client comment for the class for more details.
Parameters:
  posixPermissions - the permissions for this directory, e.g., "0700".
public  voidmv(String oldPath, String newPath)
     Move a file or directory.
public  SFTPv3FileHandleopenFileRO(String fileName)
     Open a file for reading.
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
public  SFTPv3FileHandleopenFileRW(String fileName)
     Open a file for reading and writing.
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
public  intread(SFTPv3FileHandle handle, long fileOffset, byte[] dst, int dstoff, int len)
     Read bytes from a file.
public  StringreadLink(String path)
     Read the target of a symbolic link.
Parameters:
  path - See the SFTPv3Client comment for the class for more details.
public  voidrm(String fileName)
     Remove a file.
public  voidrmdir(String dirName)
     Remove an empty directory.
public  voidsetCharset(String charset)
     Set the charset used to convert between Java Unicode Strings and byte encodings used by the server for paths and file names.
public  voidsetstat(String path, SFTPv3FileAttributes attr)
     Modify the attributes of a file.
public  SFTPv3FileAttributesstat(String path)
     Retrieve the file attributes of a file.
public  voidwrite(SFTPv3FileHandle handle, long fileOffset, byte[] src, int srcoff, int len)
     Write bytes to a file.

Field Detail
charsetName
String charsetName(Code)



conn
final Connection conn(Code)



debug
final PrintStream debug(Code)



flag_closed
boolean flag_closed(Code)



is
InputStream is(Code)



next_request_id
int next_request_id(Code)



os
OutputStream os(Code)



protocol_version
int protocol_version(Code)



server_extensions
HashMap server_extensions(Code)



sess
final Session sess(Code)




Constructor Detail
SFTPv3Client
public SFTPv3Client(Connection conn, PrintStream debug) throws IOException(Code)
Create a SFTP v3 client.
Parameters:
  conn - The underlying SSH-2 connection to be used.
Parameters:
  debug -
throws:
  IOException - SFTPv3Client.SFTPv3Client(Connection)



SFTPv3Client
public SFTPv3Client(Connection conn) throws IOException(Code)
Create a SFTP v3 client.
Parameters:
  conn - The underlying SSH-2 connection to be used.
throws:
  IOException -




Method Detail
canonicalPath
public String canonicalPath(String path) throws IOException(Code)
Have the server canonicalize any given path name to an absolute path. This is useful for converting path names containing ".." components or relative pathnames without a leading slash into absolute paths.
Parameters:
  path - See the SFTPv3Client comment for the class for more details. An absolute path.
throws:
  IOException -



close
public void close()(Code)
Close this SFTP session. NEVER forget to call this method to free up resources - even if you got an exception from one of the other methods. Sometimes these other methods may throw an exception, saying that the underlying channel is closed (this can happen, e.g., if the other server sent a close message.) However, as long as you have not called the close() method, you are likely wasting resources.



closeFile
public void closeFile(SFTPv3FileHandle handle) throws IOException(Code)
Close a file.
Parameters:
  handle - a SFTPv3FileHandle handle
throws:
  IOException -



createFile
public SFTPv3FileHandle createFile(String fileName) throws IOException(Code)
Create a file and open it for reading and writing. Same as SFTPv3Client.createFile(String,SFTPv3FileAttributes) createFile(fileName, null) .
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details. a SFTPv3FileHandle handle
throws:
  IOException -



createFile
public SFTPv3FileHandle createFile(String fileName, SFTPv3FileAttributes attr) throws IOException(Code)
Create a file and open it for reading and writing. You can specify the default attributes of the file (the server may or may not respect your wishes).
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
Parameters:
  attr - may be null to use server defaults. Probably onlythe uid, gid and permissions(remember the server may apply a umask) entries of the SFTPv3FileHandlestructure make sense. You need only to set those fields where you wantto override the server's defaults. a SFTPv3FileHandle handle
throws:
  IOException -



createFileTruncate
public SFTPv3FileHandle createFileTruncate(String fileName) throws IOException(Code)
Create a file (truncate it if it already exists) and open it for reading and writing. Same as SFTPv3Client.createFileTruncate(String,SFTPv3FileAttributes) createFileTruncate(fileName, null) .
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details. a SFTPv3FileHandle handle
throws:
  IOException -



createFileTruncate
public SFTPv3FileHandle createFileTruncate(String fileName, SFTPv3FileAttributes attr) throws IOException(Code)
reate a file (truncate it if it already exists) and open it for reading and writing. You can specify the default attributes of the file (the server may or may not respect your wishes).
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
Parameters:
  attr - may be null to use server defaults. Probably onlythe uid, gid and permissions(remember the server may apply a umask) entries of the SFTPv3FileHandlestructure make sense. You need only to set those fields where you wantto override the server's defaults. a SFTPv3FileHandle handle
throws:
  IOException -



createSymlink
public void createSymlink(String src, String target) throws IOException(Code)
Create a symbolic link on the server. Creates a link "src" that points to "target".
Parameters:
  src - See the SFTPv3Client comment for the class for more details.
Parameters:
  target - See the SFTPv3Client comment for the class for more details.
throws:
  IOException -



fsetstat
public void fsetstat(SFTPv3FileHandle handle, SFTPv3FileAttributes attr) throws IOException(Code)
Modify the attributes of a file. Used for operations such as changing the ownership, permissions or access times, as well as for truncating a file.
Parameters:
  handle - a SFTPv3FileHandle handle
Parameters:
  attr - A SFTPv3FileAttributes object. Specifies the modifications to bemade to the attributes of the file. Empty fields will be ignored.
throws:
  IOException -



fstat
public SFTPv3FileAttributes fstat(SFTPv3FileHandle handle) throws IOException(Code)
Retrieve the file attributes of an open file.
Parameters:
  handle - a SFTPv3FileHandle handle. a SFTPv3FileAttributes object.
throws:
  IOException -



getCharset
public String getCharset()(Code)
The currently used charset for filename encoding/decoding.
See Also:   SFTPv3Client.setCharset(String) The name of the charset (null if the platform's default charset is being used)



getProtocolVersion
public int getProtocolVersion()(Code)
Returns the negotiated SFTP protocol version between the client and the server. SFTP protocol version, i.e., "3".



ls
public Vector ls(String dirName) throws IOException(Code)
List the contents of a directory.
Parameters:
  dirName - See the SFTPv3Client comment for the class for more details. A Vector containing SFTPv3DirectoryEntry objects.
throws:
  IOException -



lstat
public SFTPv3FileAttributes lstat(String path) throws IOException(Code)
Retrieve the file attributes of a file. This method does NOT follow symbolic links on the server.
See Also:   SFTPv3Client.stat(String)
Parameters:
  path - See the SFTPv3Client comment for the class for more details. a SFTPv3FileAttributes object.
throws:
  IOException -



mkdir
public void mkdir(String dirName, int posixPermissions) throws IOException(Code)
Create a new directory.
Parameters:
  dirName - See the SFTPv3Client comment for the class for more details.
Parameters:
  posixPermissions - the permissions for this directory, e.g., "0700". The serverwill likely apply a umask.
throws:
  IOException -



mv
public void mv(String oldPath, String newPath) throws IOException(Code)
Move a file or directory.
Parameters:
  oldPath - See the SFTPv3Client comment for the class for more details.
Parameters:
  newPath - See the SFTPv3Client comment for the class for more details.
throws:
  IOException -



openFileRO
public SFTPv3FileHandle openFileRO(String fileName) throws IOException(Code)
Open a file for reading.
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details. a SFTPv3FileHandle handle
throws:
  IOException -



openFileRW
public SFTPv3FileHandle openFileRW(String fileName) throws IOException(Code)
Open a file for reading and writing.
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details. a SFTPv3FileHandle handle
throws:
  IOException -



read
public int read(SFTPv3FileHandle handle, long fileOffset, byte[] dst, int dstoff, int len) throws IOException(Code)
Read bytes from a file. No more than 32768 bytes may be read at once. Be aware that the semantics of read() are different than for Java streams.

  • The server will read as many bytes as it can from the file (up to len), and return them.
  • If EOF is encountered before reading any data, -1 is returned.
  • If an error occurs, an exception is thrown
  • .
  • For normal disk files, it is guaranteed that the server will return the specified number of bytes, or up to end of file. For, e.g., device files this may return fewer bytes than requested.

Parameters:
  handle - a SFTPv3FileHandle handle
Parameters:
  fileOffset - offset (in bytes) in the file
Parameters:
  dst - the destination byte array
Parameters:
  dstoff - offset in the destination byte array
Parameters:
  len - how many bytes to read, 0 < len <= 32768 bytes the number of bytes that could be read, may be less than requested ifthe end of the file is reached, -1 is returned in case of EOF
throws:
  IOException -



readLink
public String readLink(String path) throws IOException(Code)
Read the target of a symbolic link.
Parameters:
  path - See the SFTPv3Client comment for the class for more details. The target of the link.
throws:
  IOException -



rm
public void rm(String fileName) throws IOException(Code)
Remove a file.
Parameters:
  fileName - See the SFTPv3Client comment for the class for more details.
throws:
  IOException -



rmdir
public void rmdir(String dirName) throws IOException(Code)
Remove an empty directory.
Parameters:
  dirName - See the SFTPv3Client comment for the class for more details.
throws:
  IOException -



setCharset
public void setCharset(String charset) throws IOException(Code)
Set the charset used to convert between Java Unicode Strings and byte encodings used by the server for paths and file names. Unfortunately, the SFTP v3 draft says NOTHING about such conversions (well, with the exception of error messages which have to be in UTF-8). Newer drafts specify to use UTF-8 for file names (if I remember correctly). However, a quick test using OpenSSH serving a EXT-3 filesystem has shown that UTF-8 seems to be a bad choice for SFTP v3 (tested with filenames containing german umlauts). "windows-1252" seems to work better for Europe. Luckily, "windows-1252" is the platform default in my case =).

If you don't set anything, then the platform default will be used (this is the default behavior).
See Also:   SFTPv3Client.getCharset()
Parameters:
  charset - the name of the charset to be used or null to use the platform'sdefault encoding.
throws:
  IOException -




setstat
public void setstat(String path, SFTPv3FileAttributes attr) throws IOException(Code)
Modify the attributes of a file. Used for operations such as changing the ownership, permissions or access times, as well as for truncating a file.
Parameters:
  path - See the SFTPv3Client comment for the class for more details.
Parameters:
  attr - A SFTPv3FileAttributes object. Specifies the modifications to bemade to the attributes of the file. Empty fields will be ignored.
throws:
  IOException -



stat
public SFTPv3FileAttributes stat(String path) throws IOException(Code)
Retrieve the file attributes of a file. This method follows symbolic links on the server.
See Also:   SFTPv3Client.lstat(String)
Parameters:
  path - See the SFTPv3Client comment for the class for more details. a SFTPv3FileAttributes object.
throws:
  IOException -



write
public void write(SFTPv3FileHandle handle, long fileOffset, byte[] src, int srcoff, int len) throws IOException(Code)
Write bytes to a file. If len > 32768, then the write operation will be split into multiple writes.
Parameters:
  handle - a SFTPv3FileHandle handle.
Parameters:
  fileOffset - offset (in bytes) in the file.
Parameters:
  src - the source byte array.
Parameters:
  srcoff - offset in the source byte array.
Parameters:
  len - how many bytes to write.
throws:
  IOException -



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.