blob: 5d334e67f7259aefb3fa9aa12eac61818d8ee0ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/*
* Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.transport;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
/**
* An interface providing FTP operations over a {@link RemoteSession}. All
* operations are supposed to throw {@link FtpException} for remote file system
* errors and other IOExceptions on connection errors.
*
* @since 5.2
*/
public interface FtpChannel {
/**
* An {@link Exception} for reporting SFTP errors.
*/
static class FtpException extends IOException {
private static final long serialVersionUID = 7176525179280330876L;
public static final int OK = 0;
public static final int EOF = 1;
public static final int NO_SUCH_FILE = 2;
public static final int NO_PERMISSION = 3;
public static final int UNSPECIFIED_FAILURE = 4;
public static final int PROTOCOL_ERROR = 5;
public static final int UNSUPPORTED = 8;
private final int status;
public FtpException(String message, int status) {
super(message);
this.status = status;
}
public FtpException(String message, int status, Throwable cause) {
super(message, cause);
this.status = status;
}
public int getStatus() {
return status;
}
}
/**
* Connects the {@link FtpChannel} to the remote end.
*
* @param timeout
* for establishing the FTP connection
* @param unit
* of the {@code timeout}
* @throws IOException
* if an IO error occurred
*/
void connect(int timeout, TimeUnit unit) throws IOException;
/**
* Disconnects and {@link FtpChannel}.
*/
void disconnect();
/**
* Whether the FtpChannel is connected
*
* @return whether the {@link FtpChannel} is connected
*/
boolean isConnected();
/**
* Changes the current remote directory.
*
* @param path
* target directory
* @throws IOException
* if the operation could not be performed remotely
*/
void cd(String path) throws IOException;
/**
* Get current remote directory path
*
* @return the current remote directory path
* @throws IOException
* if an IO error occurred
*/
String pwd() throws IOException;
/**
* Simplified remote directory entry.
*/
interface DirEntry {
String getFilename();
long getModifiedTime();
boolean isDirectory();
}
/**
* Lists contents of a remote directory
*
* @param path
* of the directory to list
* @return the directory entries
* @throws IOException
* if an IO error occurred
*/
Collection<DirEntry> ls(String path) throws IOException;
/**
* Deletes a directory on the remote file system. The directory must be
* empty.
*
* @param path
* to delete
* @throws IOException
* if an IO error occurred
*/
void rmdir(String path) throws IOException;
/**
* Creates a directory on the remote file system.
*
* @param path
* to create
* @throws IOException
* if an IO error occurred
*/
void mkdir(String path) throws IOException;
/**
* Obtain an {@link InputStream} to read the contents of a remote file.
*
* @param path
* of the file to read
*
* @return the stream to read from
* @throws IOException
* if an IO error occurred
*/
InputStream get(String path) throws IOException;
/**
* Obtain an {@link OutputStream} to write to a remote file. If the file
* exists already, it will be overwritten.
*
* @param path
* of the file to read
*
* @return the stream to read from
* @throws IOException
* if an IO error occurred
*/
OutputStream put(String path) throws IOException;
/**
* Deletes a file on the remote file system.
*
* @param path
* to delete
* @throws IOException
* if the file does not exist or could otherwise not be deleted
*/
void rm(String path) throws IOException;
/**
* Deletes a file on the remote file system. If the file does not exist, no
* exception is thrown.
*
* @param path
* to delete
* @throws IOException
* if the file exist but could not be deleted
*/
default void delete(String path) throws IOException {
try {
rm(path);
} catch (FileNotFoundException e) {
// Ignore; it's OK if the file doesn't exist
} catch (FtpException f) {
if (f.getStatus() == FtpException.NO_SUCH_FILE) {
return;
}
throw f;
}
}
/**
* Renames a file on the remote file system. If {@code to} exists, it is
* replaced by {@code from}. (POSIX rename() semantics)
*
* @param from
* original name of the file
* @param to
* new name of the file
* @throws IOException
* if an IO error occurred
* @see <a href=
* "http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html">stdio.h:
* rename()</a>
*/
void rename(String from, String to) throws IOException;
}
|