FtpURI.st
changeset 1518 2e021f09320f
parent 1434 b415dec41ae1
child 2872 88dbc60ee0b3
--- a/FtpURI.st	Fri Jan 28 10:11:31 2005 +0100
+++ b/FtpURI.st	Tue Feb 01 13:41:37 2005 +0100
@@ -42,6 +42,24 @@
     ^ #(ftp)
 ! !
 
+!FtpURI class methodsFor:'ftp requests'!
+
+pathExists:aPathname ftpClient:aFtpClient
+
+    |stream ok|
+
+    FTPClient fileNotFoundErrorSignal handle:[:ex|] do:[
+	stream := aFtpClient getStreamFor:aPathname.
+    ].
+
+    ok := stream notNil.
+    stream notNil ifTrue:[
+	stream close
+    ].
+
+    ^ ok
+! !
+
 !FtpURI methodsFor:'defaults'!
 
 defaultPassword
@@ -79,48 +97,6 @@
             ftp close.
         ].
     ]
-!
-
-exists
-    "does the file represented by this uri exist?
-     establish a connection for try to get a readStream"
-
-    |exists|
-
-    self connectThenDo:[:aFtpClient|
-        exists := self pathExistsFtp:aFtpClient.
-    ].
-
-    ^ exists ? false
-
-"
-    |pwd uri|
-
-    pwd := Dialog requestPassword:'Password:'. 
-    uri := (URI fromString:('ftp://tm:%1@exept/home/tm/tmp/test.txt' bindWith:pwd) ).
-    uri pathExists
-"
-!
-
-pathExists:aPathname ftpClient:aFtpClient
-
-    |stream ok|
-
-    FTPClient fileNotFoundErrorSignal handle:[:ex|] do:[
-	stream := aFtpClient getStreamFor:aPathname.
-    ].
-
-    ok := stream notNil.
-    stream notNil ifTrue:[
-	stream close
-    ].
-
-    ^ ok
-!
-
-pathExistsFtp:aFtpClient
-
-    ^ self pathExists:self path ftpClient:aFtpClient
 ! !
 
 !FtpURI methodsFor:'stream access'!
@@ -146,7 +122,7 @@
     ].
 
     "
-     'ftp://stefan:password@hippo/etc/group' asURI readStreamDo:[:stream :attributes | 
+     'ftp://stefan:password@ftp.exept.de/etc/group' asURI readStreamDo:[:stream :attributes | 
          self halt
       ].
     "
@@ -189,7 +165,7 @@
 
     requestDirectory := false.
     path := self path.
-    "kludge"
+    "kludge for pathnames starting with a users home dirctory"
     (path startsWith:'/~') ifTrue:[
         path := path copyFrom:2.
     ].
@@ -205,7 +181,7 @@
             requestDirectory := true.
             dirUri  := self directory.
             dirPath := dirUri path.
-            "kludge"
+            "kludge for pathnames starting with a users home dirctory"
             (dirPath startsWith:'/~') ifTrue:[
                 dirPath := dirPath copyFrom:2.
             ].
@@ -234,7 +210,7 @@
         requestDirectory ifFalse:[
             dirUri := self directory.
             dirPath := dirUri path.
-            "kludge"
+            "kludge for pathnames starting with a users home dirctory"
             (dirPath startsWith:'/~') ifTrue:[
                 dirPath := dirPath copyFrom:2.
             ].
@@ -334,67 +310,88 @@
 
      If doCreate is true, a nonExistent directory will be created.
      If doAtomic is true, files will appear atomically, by using
-	an intermediate file theat will be renamed"
+        an intermediate file theat will be renamed"
 
     |path toPath directory|
 
     path := self path.
     "kludge"
     (path startsWith:'/~') ifTrue:[
-	path := path copyFrom:2.
+        path := path copyFrom:2.
     ].
 
     doAtomic ifTrue:[
-	toPath := self directoryPath, '/.transferFile'.
-	"kludge"
-	(toPath startsWith:'/~') ifTrue:[
-	    toPath := toPath copyFrom:2.
-	].
+        toPath := self directoryPath, '/.transferFile'.
+        "kludge"
+        (toPath startsWith:'/~') ifTrue:[
+            toPath := toPath copyFrom:2.
+        ].
     ] ifFalse:[
-	toPath := path.
+        toPath := path.
     ].
         
     self connectThenDo:[:ftp| |stream|
-	[
-	    [
-		(self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream|
-		    infoStream := '' writeStream.
-		    self publicPrintOn:infoStream.
-		    self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents).
-		].
-		stream := ftp putStreamFor:toPath.
-	    ] on:FTPClient filePutErrorSignal do:[:ex|
-		doCreate ifFalse:[
-		    ex reject
-		].
-		"create the missing directory on the fly"
-		directory := self directoryPath.
-		FTPClient fileNotFoundErrorSignal handle:[:ex| ] do:[
-		    ftp mkdir:directory.
-		].
-		ftp cd:directory.
-		(self pathExists:path ftpClient:ftp) ifTrue:[ |infoStream|
-		    infoStream := '' writeStream.
-		    self publicPrintOn:infoStream.
-		    self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents).
-		].
-		stream := ftp putStreamFor:toPath.
-	    ].
-	    aBlock value:stream value:self class attributes.
-	    stream close.
-	    doAtomic ifTrue:[
-		ftp rename:toPath to:path
-	    ].
-	] ifCurtailed:[
-	    stream notNil ifTrue:[
-		stream close.
-	    ].
-	].
+        [
+            [
+                (self class pathExists:path ftpClient:ftp) ifTrue:[ |infoStream|
+                    infoStream := '' writeStream.
+                    self publicPrintOn:infoStream.
+                    self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents).
+                ].
+                stream := ftp putStreamFor:toPath.
+            ] on:FTPClient filePutErrorSignal do:[:ex|
+                doCreate ifFalse:[
+                    ex reject
+                ].
+                "create the missing directory on the fly"
+                directory := self directoryPath.
+                FTPClient fileNotFoundErrorSignal handle:[:ex| ] do:[
+                    ftp mkdir:directory.
+                ].
+                ftp cd:directory.
+                (self class pathExists:path ftpClient:ftp) ifTrue:[ |infoStream|
+                    infoStream := '' writeStream.
+                    self publicPrintOn:infoStream.
+                    self error:('FTP write: Datei %1 already exists!!' bindWith:infoStream contents).
+                ].
+                stream := ftp putStreamFor:toPath.
+            ].
+            aBlock value:stream value:self class attributes.
+            stream close.
+            doAtomic ifTrue:[
+                ftp rename:toPath to:path
+            ].
+        ] ifCurtailed:[
+            stream notNil ifTrue:[
+                stream close.
+            ].
+        ].
     ]
 ! !
 
 !FtpURI methodsFor:'testing'!
 
+exists
+    "does the file represented by this uri exist?
+     establish a connection for try to get a readStream"
+
+    |exists|
+
+    self connectThenDo:[:aFtpClient|
+        exists :=  self class pathExists:self path ftpClient:aFtpClient
+    ].
+
+    ^ exists ? false
+
+"
+    |pwd uri|
+
+    pwd := Dialog requestPassword:'Password:'. 
+    uri := (URI fromString:('ftp://tm:%1@exept/home/tm/tmp/test.txt' bindWith:pwd) ).
+    uri pathExists
+"
+!
+
 isAbsolute
     "there is nothing like a relative ftp URI"
 
@@ -410,5 +407,5 @@
 !FtpURI class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.16 2004-03-20 15:36:05 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.17 2005-02-01 12:41:37 stefan Exp $'
 ! !