'From Squeak3.11alpha of 13 February 2010 [latest update: #9371] on 16 February 2010 at 11:58:32 am'! HierarchicalUrl subclass: #FtpUrl instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Network-Url'! !FtpUrl commentStamp: 'ls 6/15/2003 13:44' prior: 0! a reference to a file which may be downloaded by anonymous ftp . TODO: use the username and password, if specified ! !FtpUrl methodsFor: 'access' stamp: 'ls 7/24/1998 00:18'! pathString self path isEmpty ifTrue: [ ^'/' copy ]. ^String streamContents: [ :s | self path do: [ :p | s nextPut: $/. s nextPutAll: p ] ]! ! !FtpUrl methodsFor: 'downloading' stamp: 'mir 8/5/2004 11:55'! downloadUrl "Returns a http download url for the location defined by this url." | ans | ans := WriteStream on: String new. ans nextPutAll: self schemeName. ans nextPutAll: '://'. ans nextPutAll: self authority. port ifNotNil: [ans nextPut: $:; print: port]. path do: [ :pathElem | ans nextPut: $/. ans nextPutAll: pathElem encodeForHTTP. ]. self query isNil ifFalse: [ ans nextPut: $?. ans nextPutAll: self query. ]. self fragment isNil ifFalse: [ ans nextPut: $#. ans nextPutAll: self fragment encodeForHTTP. ]. ^ans contents! ! !FtpUrl methodsFor: 'downloading' stamp: 'mir 6/27/2003 19:42'! retrieveContents "currently assumes directories end in /, and things that don't end in / are files. Also, doesn't handle errors real well...." | server contents pathString listing auth idx fileName serverName userName password | pathString := self pathString. pathString := pathString copyFrom: 2 to: pathString size. "remove the leading /" pathString last = $/ ifTrue:["directory?!!" fileName := nil. ] ifFalse:[ fileName := pathString copyFrom: (pathString lastIndexOf: $/)+1 to: pathString size. pathString := pathString copyFrom: 1 to: (pathString lastIndexOf: $/) - 1. ]. auth := self authority. idx := auth indexOf: $@. idx > 0 ifTrue:[ serverName := (auth copyFrom: idx+1 to: auth size). userName := (auth copyFrom: 1 to: idx-1). password := nil. ] ifFalse:[ serverName := auth. userName := 'anonymous'. password := 'SqueakUser'. ]. server := ServerDirectory servers detect:[:s| s isTypeFTP and:[s server asLowercase = serverName asLowercase]] ifNone:[nil]. server ifNil:[ server := ServerDirectory new. server server: serverName. ] ifNotNil:[server := server copy reset]. server user: userName. password ifNotNil:[server password: password]. server directory: pathString. fileName == nil ifFalse:[ "a file" contents := (server getFileNamed: fileName). server sleep. ^MIMEDocument contentType: (MIMEDocument guessTypeFromName: self path last) content: contents]. "a directory?" listing := String streamContents: [ :stream | stream nextPutAll: '