author | tm |
Thu, 24 Jul 2003 11:29:43 +0200 | |
changeset 1284 | 57550436b55b |
parent 1276 | fd3f0d37513c |
child 1286 | cbf02dc8ddef |
permissions | -rw-r--r-- |
1005 | 1 |
"{ Package: 'stx:libbasic2' }" |
2 |
||
3 |
HierarchicalURI subclass:#FtpURI |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'Resources' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!FtpURI class methodsFor:'accessing'! |
|
12 |
||
13 |
schemes |
|
14 |
||
15 |
^ #(ftp) |
|
16 |
! ! |
|
17 |
||
18 |
!FtpURI methodsFor:'defaults'! |
|
19 |
||
20 |
defaultPassword |
|
21 |
||
22 |
^ 'secret@secret' |
|
23 |
! |
|
24 |
||
25 |
defaultPort |
|
26 |
"answer the default command-port here" |
|
27 |
||
28 |
^ 21 |
|
29 |
! |
|
30 |
||
31 |
defaultUser |
|
32 |
||
33 |
^ 'anonymous' |
|
34 |
! ! |
|
35 |
||
1258 | 36 |
!FtpURI methodsFor:'ftp requests'! |
37 |
||
38 |
connectThenDo:aOneArgBlock |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
39 |
"setup a ftp connection and call aOneArgBlock with it" |
1258 | 40 |
|
41 |
|ftp| |
|
42 |
||
43 |
ftp := FTPClient new. |
|
44 |
[ |
|
45 |
ftp connectTo:self host |
|
46 |
port:self port |
|
47 |
user:(self user ? self defaultUser) |
|
48 |
password:(self password ? self defaultPassword). |
|
49 |
aOneArgBlock value:ftp |
|
50 |
] ensure:[ |
|
51 |
ftp notNil ifTrue:[ |
|
52 |
ftp close. |
|
53 |
]. |
|
54 |
] |
|
55 |
! |
|
1254 | 56 |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
57 |
exists |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
58 |
"does the file represented by this uri exist? |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
59 |
establish a connection for try to get a readStream" |
1254 | 60 |
|
61 |
|exists| |
|
62 |
||
1258 | 63 |
self connectThenDo:[:aFtpClient| |
64 |
exists := self pathExistsFtp:aFtpClient. |
|
1254 | 65 |
]. |
66 |
||
1258 | 67 |
^ exists ? false |
1254 | 68 |
|
1258 | 69 |
" |
70 |
|pwd uri| |
|
71 |
||
72 |
pwd := Dialog requestPassword:'Password:'. |
|
73 |
uri := (URI fromString:('ftp://tm:%1@exept/home/tm/tmp/test.txt' bindWith:pwd) ). |
|
74 |
uri pathExists |
|
75 |
" |
|
76 |
! |
|
77 |
||
78 |
pathExists:aPathname ftpClient:aFtpClient |
|
79 |
||
1284 | 80 |
|stream ok| |
81 |
||
82 |
FTPClient fileNotFoundErrorSignal handle:[:ex|] do:[ |
|
83 |
stream := aFtpClient getStreamFor:aPathname. |
|
84 |
]. |
|
1258 | 85 |
|
1284 | 86 |
ok := stream notNil. |
87 |
stream notNil ifTrue:[ |
|
88 |
stream close |
|
89 |
]. |
|
90 |
||
91 |
^ ok |
|
1258 | 92 |
! |
93 |
||
94 |
pathExistsFtp:aFtpClient |
|
95 |
||
96 |
^ self pathExists:self path ftpClient:aFtpClient |
|
97 |
! ! |
|
98 |
||
1005 | 99 |
!FtpURI methodsFor:'stream access'! |
100 |
||
101 |
readStreamDo:aBlock |
|
102 |
"use FTPClient for now" |
|
103 |
||
1254 | 104 |
self connectThenDo:[:ftp| |stream path attributes| |
105 |
[ |
|
106 |
path := self path. |
|
107 |
attributes := self class attributes. |
|
108 |
attributes at:#fileSize put:(ftp sizeOf:path). |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
109 |
attributes at:#baseName put:self pathSegments last. |
1254 | 110 |
attributes at:#uriInfo put:self printString. |
111 |
||
112 |
stream := ftp getStreamFor:path. |
|
113 |
aBlock value:stream value:attributes. |
|
114 |
] ensure:[ |
|
115 |
stream notNil ifTrue:[ |
|
116 |
stream close. |
|
117 |
]. |
|
118 |
]. |
|
119 |
]. |
|
1005 | 120 |
|
1254 | 121 |
" |
1268 | 122 |
'ftp://stefan:password@hippo/etc/group' asURI readStreamDo:[:stream :attributes | |
1254 | 123 |
self halt |
124 |
]. |
|
125 |
" |
|
126 |
! |
|
127 |
||
128 |
readStreamsDo:aBlock |
|
129 |
"evaluate the block with a Collection of streams as first argument |
|
130 |
and a dictionary containing attributes as second argument, |
|
131 |
- a collection with a stream on a single file, |
|
132 |
- or a collection with streams on a directorie's files, but not recursive |
|
133 |
||
134 |
The streams are closed after aBlock has been evaluated. |
|
135 |
Attributes may be the mime type (key #MIME)" |
|
136 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
137 |
self readStreamsDo:aBlock skipFilenamesWithSuffix:nil renameBlock:nil |
1258 | 138 |
! |
139 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
140 |
readStreamsDo:aBlock renameBlock:renameBlock |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
141 |
"evaluate the block with a Collection of streams as first argument |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
142 |
and a dictionary containing attributes as second argument, |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
143 |
- a collection with a stream on a single file, |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
144 |
- or a collection with streams on a directorie's files, but not recursive |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
145 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
146 |
The streams are closed after aBlock has been evaluated. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
147 |
Attributes may be the mime type (key #MIME)" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
148 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
149 |
self readStreamsDo:aBlock skipFilenamesWithSuffix:nil renameBlock:renameBlock |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
150 |
! |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
151 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
152 |
readStreamsDo:aBlock skipFilenamesWithSuffix:skipSuffix renameBlock:renameBlock |
1258 | 153 |
"evaluate the block with a Collection of streams as first argument |
154 |
and a dictionary containing attributes as second argument, |
|
155 |
- a collection with a stream on a single file, |
|
156 |
- or a collection with streams on a directorie's files, but not recursive |
|
157 |
||
158 |
The streams are closed after aBlock has been evaluated. |
|
159 |
Attributes may be the mime type (key #MIME)" |
|
160 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
161 |
|attributes list requestDirectory path dirUri dirPath| |
1254 | 162 |
|
163 |
requestDirectory := false. |
|
164 |
path := self path. |
|
1268 | 165 |
"kludge" |
166 |
(path startsWith:'/~') ifTrue:[ |
|
167 |
path := path copyFrom:2. |
|
168 |
]. |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
169 |
|
1254 | 170 |
attributes := self class attributes. |
171 |
list := OrderedCollection new. |
|
172 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
173 |
self connectThenDo:[:ftp| |baseName| |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
174 |
"try to change directory to path. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
175 |
If we get a file error, we know that the directory does not exist" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
176 |
baseName := self baseName. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
177 |
(baseName includesAny:'*?[]') ifTrue:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
178 |
requestDirectory := true. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
179 |
dirUri := self directory. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
180 |
dirPath := dirUri path. |
1275
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
181 |
"kludge" |
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
182 |
(dirPath startsWith:'/~') ifTrue:[ |
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
183 |
dirPath := dirPath copyFrom:2. |
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
184 |
]. |
1266 | 185 |
ftp cd:dirPath. |
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
186 |
list addAll: |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
187 |
(ftp nlist select:[:filenameString| filenameString matches:baseName]). |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
188 |
] ifFalse:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
189 |
[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
190 |
dirUri := self. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
191 |
dirPath := path. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
192 |
ftp cd:dirPath. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
193 |
requestDirectory := true. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
194 |
list addAll:ftp nlist. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
195 |
] on:FTPClient fileErrorSignal do:[:ex| |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
196 |
"no directory, fetch path istSelf" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
197 |
]. |
1005 | 198 |
]. |
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
199 |
requestDirectory ifFalse:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
200 |
dirUri := self directory. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
201 |
dirPath := dirUri path. |
1275
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
202 |
"kludge" |
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
203 |
(dirPath startsWith:'/~') ifTrue:[ |
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
204 |
dirPath := dirPath copyFrom:2. |
7f2285cefdec
Tilde expansion when fetching files with wildcards
Stefan Vogel <sv@exept.de>
parents:
1271
diff
changeset
|
205 |
]. |
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
206 |
ftp cd:dirPath. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
207 |
list add:self baseName. |
1264 | 208 |
]. |
209 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
210 |
attributes at:#requestDirectory put:requestDirectory. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
211 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
212 |
"skip all files with skipSuffix aka 'file.old'" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
213 |
skipSuffix size == 0 ifFalse:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
214 |
list := list select:[:baseName| (baseName endsWith:skipSuffix) not] |
1264 | 215 |
]. |
216 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
217 |
list do:[:eachBaseName| |stream| |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
218 |
"get a stream for the contents of the file" |
1254 | 219 |
FTPClient fileErrorSignal handle:[:ex| |
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
220 |
"ignore errors -- skip subdirectories" |
1254 | 221 |
] do:[ |
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
222 |
stream := ftp getStreamFor:eachBaseName. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
223 |
attributes at:#fileSize put:(ftp sizeOf:eachBaseName). |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
224 |
attributes at:#baseName put:eachBaseName. |
1254 | 225 |
]. |
226 |
||
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
227 |
stream notNil ifTrue:[ |srcUri srcPath| |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
228 |
requestDirectory ifTrue:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
229 |
"accessing the contents of a directory" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
230 |
srcUri := dirUri construct:eachBaseName. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
231 |
] ifFalse:[ |pathSegments| |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
232 |
"accessing a single file" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
233 |
srcUri := self. |
1254 | 234 |
]. |
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
235 |
attributes at:#uriInfo put:srcUri. |
1258 | 236 |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
237 |
[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
238 |
aBlock value:stream value:attributes |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
239 |
] ensure:[stream close]. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
240 |
|
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
241 |
renameBlock notNil ifTrue:[ |renameFilenameString| |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
242 |
renameFilenameString := renameBlock value:eachBaseName. |
1284 | 243 |
"/ [ |
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
244 |
ftp rename:eachBaseName to:renameFilenameString. |
1284 | 245 |
"/ ] on:FTPClient fileErrorSignal do:[:ex| |
246 |
"/ "rename failed, maybe file already exists" |
|
247 |
"/ renameFilenameString := renameFilenameString, '.', |
|
248 |
"/ (AbsoluteTime now printStringFormat:'%(year)%(mon)%(day)%h%m%s'). |
|
249 |
"/ ftp rename:eachBaseName to:renameFilenameString. |
|
250 |
"/ ]. |
|
1258 | 251 |
]. |
1254 | 252 |
]. |
253 |
]. |
|
254 |
]. |
|
255 |
||
256 |
||
257 |
" |
|
258 |
|pwd| |
|
259 |
||
260 |
pwd := Dialog requestPassword:''. |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
261 |
(URI fromString:('ftp://tm:%1@exept/~/tmp' bindWith:pwd) ) |
1254 | 262 |
readStreamsDo:[:stream :attributes | |
263 |
Transcript showCR:(attributes at:#baseName). |
|
264 |
Transcript showCR:(attributes at:#fileSize). |
|
265 |
Transcript showCR:(attributes at:#requestDirectory). |
|
266 |
Transcript showCR:(attributes at:#uriInfo). |
|
267 |
]. |
|
268 |
" |
|
269 |
! |
|
270 |
||
271 |
writeStreamDo:aBlock |
|
272 |
"use FTPClient for now" |
|
273 |
||
274 |
self connectThenDo:[:ftp| |stream| |
|
275 |
[ |
|
276 |
stream := ftp putStreamFor:self path. |
|
277 |
aBlock value:stream value:self class attributes. |
|
278 |
] ensure:[ |
|
279 |
stream notNil ifTrue:[ |
|
280 |
stream close. |
|
281 |
]. |
|
1005 | 282 |
]. |
283 |
] |
|
1254 | 284 |
|
1005 | 285 |
" |
1268 | 286 |
'ftp://stefan:password@hippo/etc/group' asURI writeStreamDo:[:stream :attributes | |
1005 | 287 |
self halt |
288 |
]. |
|
289 |
" |
|
1266 | 290 |
! |
291 |
||
292 |
writeStreamDo:aBlock create:doCreate |
|
1268 | 293 |
|
294 |
^ self writeStreamDo:aBlock create:doCreate atomic:false. |
|
295 |
! |
|
1266 | 296 |
|
1268 | 297 |
writeStreamDo:aBlock create:doCreate atomic:doAtomic |
298 |
"use FTPClient for now. |
|
299 |
||
300 |
If doCreate is true, a nonExistent directory will be created. |
|
301 |
If doAtomic is true, files will appear atomically, by using |
|
302 |
an intermediate file theat will be renamed" |
|
303 |
||
304 |
|path toPath directory| |
|
1266 | 305 |
|
306 |
path := self path. |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
307 |
"kludge" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
308 |
(path startsWith:'/~') ifTrue:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
309 |
path := path copyFrom:2. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
310 |
]. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
311 |
|
1268 | 312 |
doAtomic ifTrue:[ |
313 |
toPath := self directoryPath, '/.transferFile'. |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
314 |
"kludge" |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
315 |
(toPath startsWith:'/~') ifTrue:[ |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
316 |
toPath := toPath copyFrom:2. |
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
317 |
]. |
1268 | 318 |
] ifFalse:[ |
319 |
toPath := path. |
|
320 |
]. |
|
321 |
||
1266 | 322 |
self connectThenDo:[:ftp| |stream| |
323 |
[ |
|
1268 | 324 |
[ |
1284 | 325 |
(self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream| |
326 |
infoStream := '' writeStream. |
|
327 |
self publicPrintOn:infoStream. |
|
328 |
self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents). |
|
329 |
]. |
|
1268 | 330 |
stream := ftp putStreamFor:toPath. |
331 |
] on:FTPClient filePutErrorSignal do:[:ex| |
|
1266 | 332 |
doCreate ifFalse:[ |
333 |
ex reject |
|
1268 | 334 |
]. |
335 |
"create the missing directory on the fly" |
|
336 |
directory := self directoryPath. |
|
1267 | 337 |
FTPClient fileNotFoundErrorSignal handle:[:ex| ] do:[ |
1268 | 338 |
ftp mkdir:directory. |
1267 | 339 |
]. |
1268 | 340 |
ftp cd:directory. |
1284 | 341 |
(self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream| |
342 |
infoStream := '' writeStream. |
|
343 |
self publicPrintOn:infoStream. |
|
344 |
self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents). |
|
345 |
]. |
|
1268 | 346 |
stream := ftp putStreamFor:toPath. |
1266 | 347 |
]. |
348 |
aBlock value:stream value:self class attributes. |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
349 |
stream close. |
1268 | 350 |
doAtomic ifTrue:[ |
351 |
ftp rename:toPath to:path |
|
352 |
]. |
|
1271
ca2e206e7c7f
Working version: tilde-expansion, patterns
Stefan Vogel <sv@exept.de>
parents:
1268
diff
changeset
|
353 |
] ifCurtailed:[ |
1266 | 354 |
stream notNil ifTrue:[ |
355 |
stream close. |
|
356 |
]. |
|
357 |
]. |
|
358 |
] |
|
1268 | 359 |
! ! |
1266 | 360 |
|
1268 | 361 |
!FtpURI methodsFor:'testing'! |
362 |
||
363 |
isAbsolute |
|
364 |
"there is nothing like a relative ftp URI" |
|
365 |
||
366 |
^ true |
|
1276 | 367 |
! |
368 |
||
369 |
isRemote |
|
370 |
"return true, if this is a remote URI" |
|
371 |
||
372 |
^ true |
|
1005 | 373 |
! ! |
374 |
||
375 |
!FtpURI class methodsFor:'documentation'! |
|
376 |
||
377 |
version |
|
1284 | 378 |
^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.12 2003-07-24 09:29:33 tm Exp $' |
1005 | 379 |
! ! |