FtpURI.st
changeset 4880 09220005946f
parent 3452 366305432727
equal deleted inserted replaced
4879:d6b8308d7c51 4880:09220005946f
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 2002 by eXept Software AG
     4  COPYRIGHT (c) 2002 by eXept Software AG
     3               All Rights Reserved
     5               All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
     9  other person.  No title to or ownership of the software is
    11  other person.  No title to or ownership of the software is
    10  hereby transferred.
    12  hereby transferred.
    11 "
    13 "
    12 "{ Package: 'stx:libbasic2' }"
    14 "{ Package: 'stx:libbasic2' }"
    13 
    15 
       
    16 "{ NameSpace: Smalltalk }"
       
    17 
    14 HierarchicalURI subclass:#FtpURI
    18 HierarchicalURI subclass:#FtpURI
    15 	instanceVariableNames:''
    19 	instanceVariableNames:''
    16 	classVariableNames:''
    20 	classVariableNames:''
    17 	poolDictionaries:''
    21 	poolDictionaries:''
    18 	category:'Net-Resources'
    22 	category:'Net-Resources'
    78 ! !
    82 ! !
    79 
    83 
    80 !FtpURI methodsFor:'ftp requests'!
    84 !FtpURI methodsFor:'ftp requests'!
    81 
    85 
    82 connectThenDo:aOneArgBlock
    86 connectThenDo:aOneArgBlock
    83     "setup a ftp connection and call aOneArgBlock with it"
    87     "setup a ftp connection and call aOneArgBlock with it.
       
    88      Ensures that the ftp connection is closed afterwards."
    84 
    89 
    85     |ftp|
    90     |ftp|
    86 
    91 
    87     ftp := FTPClient new.
    92     ftp := FTPClient new.
    88     [
    93     ^ [
    89         ftp connectTo:self host 
    94         ftp connectTo:self host 
    90             port:self port 
    95             port:self port 
    91             user:(self user ? self defaultUser)
    96             user:(self user ? self defaultUser)
    92             password:(self password ? self defaultPassword).
    97             password:(self password ? self defaultPassword).
    93         aOneArgBlock value:ftp
    98         aOneArgBlock value:ftp
    94     ] ensure:[
    99     ] ensure:[
    95         ftp notNil ifTrue:[
   100         ftp notNil ifTrue:[
    96             ftp close.
   101             ftp close.
    97         ].
   102         ].
    98     ]
   103     ]
       
   104 
       
   105     "Modified: / 18-03-2019 / 10:53:22 / Claus Gittinger"
    99 ! !
   106 ! !
   100 
   107 
   101 !FtpURI methodsFor:'stream access'!
   108 !FtpURI methodsFor:'stream access'!
   102 
   109 
   103 readStreamDo:aBlock
   110 readStreamDo:aBlock
       
   111     "evaluate a block with the read stream as first argument
       
   112      and a dictionary containing attributes as second argument.
       
   113      The stream is closed after aBlock has been evaluated."
       
   114 
   104     "use FTPClient for now"
   115     "use FTPClient for now"
   105 
   116 
   106     self connectThenDo:[:ftp| |stream path attributes|
   117     ^ self connectThenDo:[:ftp| 
       
   118         |stream|
   107         [
   119         [
       
   120             |path attributes|
       
   121             
   108             path := self path.
   122             path := self path.
   109             attributes := self class attributes.
   123             attributes := self class attributes.
   110             attributes at:#fileSize put:(ftp sizeOf:path).
   124             attributes at:#fileSize put:(ftp sizeOf:path).
   111             attributes at:#baseName put:self pathSegments last.  
   125             attributes at:#baseName put:self pathSegments last.  
   112             attributes at:#uriInfo  put:self printString.  
   126             attributes at:#uriInfo  put:self printString.  
   123     "
   137     "
   124      'ftp://stefan:password@ftp.exept.de/etc/group' asURI readStreamDo:[:stream :attributes | 
   138      'ftp://stefan:password@ftp.exept.de/etc/group' asURI readStreamDo:[:stream :attributes | 
   125          self halt
   139          self halt
   126       ].
   140       ].
   127     "
   141     "
       
   142 
       
   143     "Modified: / 18-03-2019 / 11:00:32 / Claus Gittinger"
   128 !
   144 !
   129 
   145 
   130 readStreamsDo:aBlock
   146 readStreamsDo:aBlock
   131     "evaluate the block with a Collection of streams as first argument
   147     "evaluate the block with a Collection of streams as first argument
   132      and a dictionary containing attributes as second argument,
   148      and a dictionary containing attributes as second argument,
   404 ! !
   420 ! !
   405 
   421 
   406 !FtpURI class methodsFor:'documentation'!
   422 !FtpURI class methodsFor:'documentation'!
   407 
   423 
   408 version
   424 version
   409     ^ '$Header: /cvs/stx/stx/libbasic2/FtpURI.st,v 1.20 2014-12-02 14:22:35 stefan Exp $'
   425     ^ '$Header$'
   410 ! !
   426 ! !
   411 
   427