203 baseName := self baseName. |
179 baseName := self baseName. |
204 (baseName includesAny:'*?[]') ifTrue:[ |
180 (baseName includesAny:'*?[]') ifTrue:[ |
205 requestDirectory := true. |
181 requestDirectory := true. |
206 dirUri := self directory. |
182 dirUri := self directory. |
207 dirPath := dirUri path. |
183 dirPath := dirUri path. |
208 "kludge" |
184 "kludge for pathnames starting with a users home dirctory" |
209 (dirPath startsWith:'/~') ifTrue:[ |
185 (dirPath startsWith:'/~') ifTrue:[ |
210 dirPath := dirPath copyFrom:2. |
186 dirPath := dirPath copyFrom:2. |
211 ]. |
187 ]. |
212 ftp cd:dirPath. |
188 ftp cd:dirPath. |
213 FTPClient fileNotFoundErrorSignal handle:[:ex|] |
189 FTPClient fileNotFoundErrorSignal handle:[:ex|] |
332 writeStreamDo:aBlock create:doCreate atomic:doAtomic |
308 writeStreamDo:aBlock create:doCreate atomic:doAtomic |
333 "use FTPClient for now. |
309 "use FTPClient for now. |
334 |
310 |
335 If doCreate is true, a nonExistent directory will be created. |
311 If doCreate is true, a nonExistent directory will be created. |
336 If doAtomic is true, files will appear atomically, by using |
312 If doAtomic is true, files will appear atomically, by using |
337 an intermediate file theat will be renamed" |
313 an intermediate file theat will be renamed" |
338 |
314 |
339 |path toPath directory| |
315 |path toPath directory| |
340 |
316 |
341 path := self path. |
317 path := self path. |
342 "kludge" |
318 "kludge" |
343 (path startsWith:'/~') ifTrue:[ |
319 (path startsWith:'/~') ifTrue:[ |
344 path := path copyFrom:2. |
320 path := path copyFrom:2. |
345 ]. |
321 ]. |
346 |
322 |
347 doAtomic ifTrue:[ |
323 doAtomic ifTrue:[ |
348 toPath := self directoryPath, '/.transferFile'. |
324 toPath := self directoryPath, '/.transferFile'. |
349 "kludge" |
325 "kludge" |
350 (toPath startsWith:'/~') ifTrue:[ |
326 (toPath startsWith:'/~') ifTrue:[ |
351 toPath := toPath copyFrom:2. |
327 toPath := toPath copyFrom:2. |
352 ]. |
328 ]. |
353 ] ifFalse:[ |
329 ] ifFalse:[ |
354 toPath := path. |
330 toPath := path. |
355 ]. |
331 ]. |
356 |
332 |
357 self connectThenDo:[:ftp| |stream| |
333 self connectThenDo:[:ftp| |stream| |
358 [ |
334 [ |
359 [ |
335 [ |
360 (self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream| |
336 (self class pathExists:path ftpClient:ftp) ifTrue:[ |infoStream| |
361 infoStream := '' writeStream. |
337 infoStream := '' writeStream. |
362 self publicPrintOn:infoStream. |
338 self publicPrintOn:infoStream. |
363 self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents). |
339 self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents). |
364 ]. |
340 ]. |
365 stream := ftp putStreamFor:toPath. |
341 stream := ftp putStreamFor:toPath. |
366 ] on:FTPClient filePutErrorSignal do:[:ex| |
342 ] on:FTPClient filePutErrorSignal do:[:ex| |
367 doCreate ifFalse:[ |
343 doCreate ifFalse:[ |
368 ex reject |
344 ex reject |
369 ]. |
345 ]. |
370 "create the missing directory on the fly" |
346 "create the missing directory on the fly" |
371 directory := self directoryPath. |
347 directory := self directoryPath. |
372 FTPClient fileNotFoundErrorSignal handle:[:ex| ] do:[ |
348 FTPClient fileNotFoundErrorSignal handle:[:ex| ] do:[ |
373 ftp mkdir:directory. |
349 ftp mkdir:directory. |
374 ]. |
350 ]. |
375 ftp cd:directory. |
351 ftp cd:directory. |
376 (self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream| |
352 (self class pathExists:path ftpClient:ftp) ifTrue:[ |infoStream| |
377 infoStream := '' writeStream. |
353 infoStream := '' writeStream. |
378 self publicPrintOn:infoStream. |
354 self publicPrintOn:infoStream. |
379 self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents). |
355 self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents). |
380 ]. |
356 ]. |
381 stream := ftp putStreamFor:toPath. |
357 stream := ftp putStreamFor:toPath. |
382 ]. |
358 ]. |
383 aBlock value:stream value:self class attributes. |
359 aBlock value:stream value:self class attributes. |
384 stream close. |
360 stream close. |
385 doAtomic ifTrue:[ |
361 doAtomic ifTrue:[ |
386 ftp rename:toPath to:path |
362 ftp rename:toPath to:path |
387 ]. |
363 ]. |
388 ] ifCurtailed:[ |
364 ] ifCurtailed:[ |
389 stream notNil ifTrue:[ |
365 stream notNil ifTrue:[ |
390 stream close. |
366 stream close. |
391 ]. |
367 ]. |
392 ]. |
368 ]. |
393 ] |
369 ] |
394 ! ! |
370 ! ! |
395 |
371 |
396 !FtpURI methodsFor:'testing'! |
372 !FtpURI methodsFor:'testing'! |
|
373 |
|
374 exists |
|
375 "does the file represented by this uri exist? |
|
376 establish a connection for try to get a readStream" |
|
377 |
|
378 |exists| |
|
379 |
|
380 self connectThenDo:[:aFtpClient| |
|
381 exists := self class pathExists:self path ftpClient:aFtpClient |
|
382 ]. |
|
383 |
|
384 ^ exists ? false |
|
385 |
|
386 " |
|
387 |pwd uri| |
|
388 |
|
389 pwd := Dialog requestPassword:'Password:'. |
|
390 uri := (URI fromString:('ftp://tm:%1@exept/home/tm/tmp/test.txt' bindWith:pwd) ). |
|
391 uri pathExists |
|
392 " |
|
393 ! |
397 |
394 |
398 isAbsolute |
395 isAbsolute |
399 "there is nothing like a relative ftp URI" |
396 "there is nothing like a relative ftp URI" |
400 |
397 |
401 ^ true |
398 ^ true |