Subversion Repositories Programming Utils

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 rm5248 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
package org.apache.sshd.client;
20
 
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.io.OutputStream;
24
import java.util.EnumSet;
25
 
26
/**
27
 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
28
 */
29
public interface SftpClient {
30
 
31
    //
32
    // Permission flags
33
    //
34
    int S_IFMT =   0170000;  // bitmask for the file type bitfields
35
    int S_IFSOCK = 0140000;  // socket
36
    int S_IFLNK =  0120000;  // symbolic link
37
    int S_IFREG =  0100000;  // regular file
38
    int S_IFBLK =  0060000;  // block device
39
    int S_IFDIR =  0040000;  // directory
40
    int S_IFCHR =  0020000;  // character device
41
    int S_IFIFO =  0010000;  // fifo
42
    int S_ISUID =  0004000;  // set UID bit
43
    int S_ISGID =  0002000;  // set GID bit
44
    int S_ISVTX =  0001000;  // sticky bit
45
    int S_IRUSR =  0000400;
46
    int S_IWUSR =  0000200;
47
    int S_IXUSR =  0000100;
48
    int S_IRGRP =  0000040;
49
    int S_IWGRP =  0000020;
50
    int S_IXGRP =  0000010;
51
    int S_IROTH =  0000004;
52
    int S_IWOTH =  0000002;
53
    int S_IXOTH =  0000001;
54
 
55
    enum OpenMode {
56
        Read,
57
        Write,
58
        Append,
59
        Create,
60
        Truncate,
61
        Exclusive
62
    }
63
 
64
    enum Attribute {
65
        Size,
66
        UidGid,
67
        Perms,
68
        AcModTime
69
    }
70
 
71
    public static class Handle {
72
        public final String id;
73
        public Handle(String id) {
74
            this.id = id;
75
        }
76
    }
77
 
78
    public static class Attributes {
79
        public EnumSet<Attribute> flags = EnumSet.noneOf(Attribute.class);
80
        public long size;
81
        public int uid;
82
        public int gid;
83
        public int perms;
84
        public int atime;
85
        public int mtime;
86
        public Attributes size(long size) {
87
            flags.add(Attribute.Size);
88
            this.size = size;
89
            return this;
90
        }
91
        public Attributes owner(int uid, int gid) {
92
            flags.add(Attribute.UidGid);
93
            this.uid = uid;
94
            this.gid = gid;
95
            return this;
96
        }
97
        public Attributes perms(int perms) {
98
            flags.add(Attribute.Perms);
99
            this.perms = perms;
100
            return this;
101
        }
102
        public Attributes time(int atime, int mtime) {
103
            flags.add(Attribute.AcModTime);
104
            this.atime = atime;
105
            this.mtime = mtime;
106
            return this;
107
        }
108
        public boolean isRegularFile() {
109
            return (perms & S_IFMT) == S_IFREG;
110
        }
111
        public boolean isDirectory() {
112
            return (perms & S_IFMT) == S_IFDIR;
113
        }
114
        public boolean isSymbolicLink() {
115
            return (perms & S_IFMT) == S_IFLNK;
116
        }
117
        public boolean isOther() {
118
            return !isRegularFile() && !isDirectory() && !isSymbolicLink();
119
        }
120
    }
121
 
122
    public static class DirEntry {
123
        public String filename;
124
        public String longFilename;
125
        public Attributes attributes;
126
        public DirEntry(String filename, String longFilename, Attributes attributes) {
127
            this.filename = filename;
128
            this.longFilename = longFilename;
129
            this.attributes = attributes;
130
        }
131
    }
132
 
133
    /**
134
     * Close the client.
135
     */
136
    void close() throws IOException;
137
 
138
    //
139
    // Low level API
140
    //
141
 
142
    Handle open(String path, EnumSet<OpenMode> options) throws IOException;
143
 
144
    void close(Handle handle) throws IOException;
145
 
146
    void remove(String path) throws IOException;
147
 
148
    void rename(String oldPath, String newPath) throws IOException;
149
 
150
    int read(Handle handle, long fileOffset, byte[] dst, int dstoff, int len) throws IOException;
151
 
152
    void write(Handle handle, long fileOffset, byte[] src, int srcoff, int len) throws IOException;
153
 
154
    void mkdir(String path) throws IOException;
155
 
156
    void rmdir(String path) throws IOException;
157
 
158
    Handle openDir(String path) throws IOException;
159
 
160
    DirEntry[] readDir(Handle handle) throws IOException;
161
 
162
    String canonicalPath(String canonical) throws IOException;
163
 
164
    Attributes stat(String path) throws IOException;
165
 
166
    Attributes lstat(String path) throws IOException;
167
 
168
    Attributes stat(Handle handle) throws IOException;
169
 
170
    void setStat(String path, Attributes attributes) throws IOException;
171
 
172
    void setStat(Handle handle, Attributes attributes) throws IOException;
173
 
174
    String readLink(String path) throws IOException;
175
 
176
    void symLink(String linkPath, String targetPath) throws IOException;
177
 
178
    //
179
    // High level API
180
    //
181
 
182
    Iterable<DirEntry> readDir(String path) throws IOException;
183
 
184
    InputStream read(String path) throws IOException;
185
 
186
    InputStream read(String path, EnumSet<OpenMode> mode) throws IOException;
187
 
188
    OutputStream write(String path) throws IOException;
189
 
190
    OutputStream write(String path, EnumSet<OpenMode> mode) throws IOException;
191
 
192
}