1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.commons.ssh;
17
18 import java.io.FileNotFoundException;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.OutputStream;
22 import java.util.List;
23
24 /***
25 * @author Egor Ivanov (crackcraft at gmail dot com)
26 * @since 1.2
27 * @see net.sf.commons.ssh.Features#SESSION_SFTP
28 */
29 public interface SftpSession extends Session {
30
31 /***
32 * Changes the working directory on the remote server.
33 *
34 * @param dir
35 * the new working directory
36 *
37 * @throws IOException
38 * if an IO error occurs or the file does not exist
39 * @throws FileNotFoundException
40 *
41 */
42 void cd(String dir) throws IOException;
43
44 /***
45 * Sets the group ID for the file or directory.
46 *
47 * @param gid
48 * the numeric group id for the new group
49 * @param path
50 * the path to the remote file/directory
51 *
52 * @throws IOException
53 * if an IO error occurs or the file does not exist
54 */
55 void chgrp(int gid, String path) throws IOException;
56
57 /***
58 * Changes the access permissions or modes of the specified file or
59 * directory.
60 *
61 * Modes determine who can read, change or execute a file.
62 *
63 * <blockquote>
64 *
65 * <pre>
66 * Absolute modes are octal numbers specifying the complete list of
67 * attributes for the files; you specify attributes by OR'ing together
68 * these bits.
69 *
70 * 0400 Individual read
71 * 0200 Individual write
72 * 0100 Individual execute (or list directory)
73 * 0040 Group read
74 * 0020 Group write
75 * 0010 Group execute
76 * 0004 Other read
77 * 0002 Other write
78 * 0001 Other execute
79 * </pre>
80 *
81 * </blockquote>
82 *
83 * @param permissions
84 * the absolute mode of the file/directory
85 * @param path
86 * the path to the file/directory on the remote server
87 *
88 * @throws IOException
89 * if an IO error occurs or the file if not found
90 */
91 void chmod(int permissions, String path) throws IOException;
92
93 /***
94 * Sets the user ID to owner for the file or directory.
95 *
96 * @param uid
97 * numeric user id of the new owner
98 * @param path
99 * the path to the remote file/directory
100 *
101 * @throws IOException
102 * if an IO error occurs or the file does not exist
103 */
104 void chown(int uid, String path) throws IOException;
105
106 /***
107 // * Create a directory or set of directories. This method will not fail
108 // even
109 // * if the directories exist. It is advisable to test whether the directory
110 // * exists before attempting an operation by using the <code>stat</code>
111 // * method to return the directories attributes.
112 // *
113 // * @param dir the path of directories to create.
114 // */
115
116
117 /***
118 * Download the remote file to the local computer.
119 *
120 * @param path
121 * the path to the remote file
122 *
123 * @throws IOException
124 * if an IO error occurs of the file does not exist
125 */
126 public void get(String path) throws IOException;
127
128 /***
129 * Download the remote file writing it to the specified
130 * <code>OutputStream</code>. The OutputStream is closed by this method even
131 * if the operation fails.
132 *
133 * @param remote
134 * the path/name of the remote file
135 * @param local
136 * the OutputStream to write
137 *
138 * @throws IOException
139 * if an IO error occurs or the file does not exist
140 */
141 void get(String remote, OutputStream local) throws IOException;
142
143 /***
144 * Download the remote file to the local computer. If the paths provided are
145 * not absolute the current working directory is used.
146 *
147 * @param remote
148 * the path/name of the remote file
149 * @param local
150 * the path/name of the local file
151 *
152 * @throws IOException
153 */
154 void get(String remote, String local) throws IOException;
155
156 /***
157 * @param path
158 *
159 * @return
160 *
161 * @throws IOException
162 */
163 String getAbsolutePath(String path) throws IOException;
164
165 /***
166 * Changes the local working directory.
167 *
168 * @param path
169 * the path to the new working directory
170 *
171 * @throws IOException
172 * if an IO error occurs
173 */
174 void lcd(String path) throws IOException;
175
176 /***
177 * Returns the absolute path to the local working directory.
178 *
179 * @return the absolute path of the local working directory.
180 */
181 String lpwd();
182
183 /***
184 * List the contents of the current remote working directory.
185 *
186 * @return a list of SftpFile for the current working directory
187 *
188 * @throws IOException
189 * if an IO error occurs
190 *
191 * @see SftpFile
192 */
193 List ls() throws IOException;
194
195 /***
196 * List the contents remote directory.
197 *
198 * @param path
199 * the path on the remote server to list
200 *
201 * @return a list of SftpFile for the remote directory
202 *
203 * @throws IOException
204 * if an IO error occurs
205 *
206 * @see SftpFile
207 */
208 List ls(String path) throws IOException;
209
210 /***
211 * Creates a new directory on the remote server. This method will throw an
212 * exception if the directory already exists. To create directories and
213 * disregard any errors use the <code>mkdirs</code> method.
214 *
215 * @param dir
216 * the name of the new directory
217 *
218 * @throws IOException
219 * if an IO error occurs or if the directory already exists
220 *
221 */
222 void mkdir(String dir) throws IOException;
223
224 /***
225 * @param in
226 * @param remote
227 *
228 * @throws IOException
229 */
230 void put(InputStream in, String remote) throws IOException;
231
232 /***
233 * Upload a file to the remote computer.
234 *
235 * @param local
236 * the path/name of the local file
237 *
238 * @throws IOException
239 * if an IO error occurs or the file does not exist
240 *
241 */
242 void put(String local) throws IOException;
243
244 /***
245 * Upload a file to the remote computer. If the paths provided are not
246 * absolute the current working directory is used.
247 *
248 * @param local
249 * the path/name of the local file
250 * @param remote
251 * the path/name of the destination file
252 *
253 * @throws IOException
254 * if an IO error occurs or the file does not exist
255 */
256 void put(String local, String remote) throws IOException;
257
258 /***
259 * Returns the absolute path name of the current remote working directory.
260 *
261 * @return the absolute path of the remote working directory.
262 */
263 String pwd() throws IOException;
264
265 /***
266 * Rename a file on the remote computer.
267 *
268 * @param oldpath
269 * the old path
270 * @param newpath
271 * the new path
272 *
273 * @throws IOException
274 * if an IO error occurs
275 *
276 */
277 void rename(String oldpath, String newpath) throws IOException;
278
279 /***
280 * Remove a file or directory from the remote computer.
281 *
282 * @param path
283 * the path of the remote file/directory
284 *
285 * @throws IOException
286 * if an IO error occurs
287 */
288 void rm(String path) throws IOException;
289
290 /***
291 * Returns the attributes of the file from the remote computer.
292 *
293 * @param path
294 * the path of the file on the remote computer
295 *
296 * @return the attributes
297 *
298 * @throws IOException
299 * if an IO error occurs or the file does not exist
300 *
301 * @see SftpFileAttributes
302 */
303 SftpFileAttributes stat(String path) throws IOException;
304
305 /***
306 // * @param path
307 // * @param force
308 // * @param recurse
309 // *
310 // * @throws IOException
311 // */
312
313
314 /***
315 * Create a symbolic link on the remote computer.
316 *
317 * @param path
318 * the path to the existing file
319 * @param link
320 * the new link
321 *
322 * @throws IOException
323 * if an IO error occurs or the operation is not supported on
324 * the remote platform
325 */
326 void symlink(String path, String link) throws IOException;
327
328 /***
329 * Sets the defaultPermissions used by this client.
330 *
331 * @param umask
332 */
333 void umask(int umask);
334 }