--- 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 $'
! !
--- a/URI.st Fri Jan 28 10:11:31 2005 +0100
+++ b/URI.st Tue Feb 01 13:41:37 2005 +0100
@@ -43,12 +43,17 @@
|i scheme rest|
i := aString indexOf:$:.
- i == 0 ifTrue:[
- self error:('Missing scheme in: %1!!' bindWith:aString)
+ i == 0 ifTrue:[
+ (aString startsWith:$/) ifTrue:[
+ scheme := #file.
+ rest := aString.
+ ] ifFalse:[
+ self error:('Missing scheme in: %1!!' bindWith:aString).
+ ].
+ ] ifFalse:[
+ scheme := aString copyFrom:1 to:i-1.
+ rest := aString copyFrom:i+1.
].
- scheme := aString copyFrom:1 to:i-1.
- rest := aString copyFrom:i+1.
-
^ (self classForScheme:scheme) scheme:scheme fromString:rest
@@ -294,5 +299,5 @@
!URI class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/URI.st,v 1.11 2004-03-05 19:02:22 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/URI.st,v 1.12 2005-02-01 12:41:07 stefan Exp $'
! !