FtpURI.st
changeset 1268 48b43aebf125
parent 1267 5e7f102e094d
child 1271 ca2e206e7c7f
equal deleted inserted replaced
1267:5e7f102e094d 1268:48b43aebf125
   109             ].
   109             ].
   110         ].
   110         ].
   111     ].
   111     ].
   112 
   112 
   113     "
   113     "
   114      'ftp://stefan:mschrat.14@hippo/etc/group' asURI readStreamDo:[:stream :attributes | 
   114      'ftp://stefan:password@hippo/etc/group' asURI readStreamDo:[:stream :attributes | 
   115          self halt
   115          self halt
   116       ].
   116       ].
   117     "
   117     "
   118 !
   118 !
   119 
   119 
   140 
   140 
   141     |attributes list requestDirectory path dirPath|
   141     |attributes list requestDirectory path dirPath|
   142 
   142 
   143     requestDirectory := false.
   143     requestDirectory := false.
   144     path := self path.
   144     path := self path.
       
   145     "kludge"
       
   146     (path startsWith:'/~') ifTrue:[
       
   147         path := path copyFrom:2.
       
   148     ].
   145     attributes := self class attributes.
   149     attributes := self class attributes.
   146     list := OrderedCollection new.
   150     list := OrderedCollection new.
   147 
   151 
   148     self connectThenDo:[:ftp|
   152     self connectThenDo:[:ftp|
   149         FTPClient fileErrorSignal handle:[:ex|
   153         FTPClient fileErrorSignal handle:[:ex|
   259             ].
   263             ].
   260         ].
   264         ].
   261     ]
   265     ]
   262 
   266 
   263     "
   267     "
   264      'ftp://stefan:mschrat.14@hippo/etc/group' asURI readStreamDo:[:stream :attributes | 
   268      'ftp://stefan:password@hippo/etc/group' asURI writeStreamDo:[:stream :attributes | 
   265          self halt
   269          self halt
   266       ].
   270       ].
   267     "
   271     "
   268 !
   272 !
   269 
   273 
   270 writeStreamDo:aBlock create:doCreate
   274 writeStreamDo:aBlock create:doCreate
   271     "use FTPClient for now"
   275 
   272 
   276     ^ self writeStreamDo:aBlock create:doCreate atomic:false.
   273     |path absDir absPath|
   277 !
       
   278 
       
   279 writeStreamDo:aBlock create:doCreate atomic:doAtomic
       
   280     "use FTPClient for now.
       
   281 
       
   282      If doCreate is true, a nonExistent directory will be created.
       
   283      If doAtomic is true, files will appear atomically, by using
       
   284         an intermediate file theat will be renamed"
       
   285 
       
   286     |path toPath directory|
   274 
   287 
   275     path := self path.
   288     path := self path.
   276     (path startsWith:'/') 
   289     doAtomic ifTrue:[
   277         ifTrue:[  absPath := path] 
   290         toPath := self directoryPath, '/.transferFile'.
   278         ifFalse:[ absPath := '/', path ].
   291     ] ifFalse:[
   279     absDir := absPath asFilename directory.
   292         toPath := path.
       
   293     ].
       
   294         
   280     self connectThenDo:[:ftp| |stream|
   295     self connectThenDo:[:ftp| |stream|
   281         [
   296         [
   282             ftp connectTo:self host 
   297             ftp connectTo:self host 
   283                 port:self port 
   298                 port:self port 
   284                 user:(self user ? self defaultUser)
   299                 user:(self user ? self defaultUser)
   285                 password:(self password ? self defaultPassword).
   300                 password:(self password ? self defaultPassword).
   286 
   301 
   287             FTPClient filePutErrorSignal handle:[:ex| |str|
   302             [
       
   303                 stream := ftp putStreamFor:toPath.
       
   304             ] on:FTPClient filePutErrorSignal do:[:ex|
   288                 doCreate ifFalse:[
   305                 doCreate ifFalse:[
   289                     ex reject
   306                     ex reject
   290                 ]. 
   307                 ].
       
   308                 "create the missing directory on the fly"
       
   309                 directory := self directoryPath.
   291                 FTPClient fileNotFoundErrorSignal handle:[:ex| ] do:[
   310                 FTPClient fileNotFoundErrorSignal handle:[:ex| ] do:[
   292                     ftp mkdir:absDir.
   311                     ftp mkdir:directory.
   293                 ].
   312                 ].
   294                 ftp cd:absDir.
   313                 ftp cd:directory.
   295                 stream := ftp putStreamFor:absPath.
   314                 stream := ftp putStreamFor:toPath.
   296             ] do:[
   315             ].
   297                 stream := ftp putStreamFor:absPath.
       
   298             ].
       
   299 
       
   300             aBlock value:stream value:self class attributes.
   316             aBlock value:stream value:self class attributes.
       
   317             doAtomic ifTrue:[
       
   318                 ftp rename:toPath to:path
       
   319             ].
   301         ] ensure:[
   320         ] ensure:[
   302             stream notNil ifTrue:[
   321             stream notNil ifTrue:[
   303                 stream close.
   322                 stream close.
   304             ].
   323             ].
   305         ].
   324         ].
   306     ]
   325     ]
   307 
   326 ! !
   308     "
   327 
   309      'ftp://stefan:mschrat.14@hippo/etc/group' asURI readStreamDo:[:stream :attributes | 
   328 !FtpURI methodsFor:'testing'!
   310          self halt
   329 
   311       ].
   330 isAbsolute
   312     "
   331     "there is nothing like a relative ftp URI"
       
   332 
       
   333     ^ true
   313 ! !
   334 ! !
   314 
   335 
   315 !FtpURI class methodsFor:'documentation'!
   336 !FtpURI class methodsFor:'documentation'!
   316 
   337 
   317 version
   338 version
   318     ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.7 2003-07-10 14:32:44 tm Exp $'
   339     ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.8 2003-07-11 12:48:15 stefan Exp $'
   319 ! !
   340 ! !