SftpURI.st
changeset 4878 5d852ae34bc9
parent 3639 69157be6c67d
child 4882 cdc1e27ab112
--- a/SftpURI.st	Sun Mar 17 20:15:30 2019 +0100
+++ b/SftpURI.st	Mon Mar 18 10:59:35 2019 +0100
@@ -1,3 +1,16 @@
+"{ Encoding: utf8 }"
+
+"
+ COPYRIGHT (c) 2009 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
 "{ Package: 'stx:libbasic2' }"
 
 "{ NameSpace: Smalltalk }"
@@ -66,26 +79,42 @@
 !SftpURI methodsFor:'ftp requests'!
 
 connectThenDo:aOneArgBlock
-    "setup a ftp connection and call aOneArgBlock with it"
+    "setup a ftp connection and call aOneArgBlock with it.
+     Ensures that the sftp connection is closed afterwards."
 
     |sftpClient|
 
     SftpClient isNil ifTrue:[
         Smalltalk loadPackage:'stx:goodies/communication'.
-    ].    
-    sftpClient := SftpClient new
-                hostname:self host;
-                username:self user;
-                port:self port.
+    ].
+    ^ [
+        sftpClient := SftpClient new
+                    hostname:self host;
+                    username:self user;
+                    port:self port.
 
-    aOneArgBlock value:sftpClient.
+        aOneArgBlock value:sftpClient.
+    ] ensure:[
+        sftpClient notNil ifTrue:[
+            sftpClient close
+        ]
+    ].
+
+    "Modified: / 18-03-2019 / 10:54:22 / Claus Gittinger"
 ! !
 
 !SftpURI methodsFor:'stream access'!
 
 readStreamDo:aBlock
-    self connectThenDo:[:ftp| |stream path attributes|
+    "evaluate a block with the read stream as first argument
+     and a dictionary containing attributes as second argument.
+     The stream is closed after aBlock has been evaluated."
+
+    self connectThenDo:[:ftp| 
+        |stream|
         [
+            |path attributes|
+            
             path := self path.
             attributes := self class attributes.
             attributes at:#fileSize put:(ftp sizeOf:path).
@@ -106,6 +135,8 @@
          self halt
       ].
     "
+
+    "Modified (comment): / 18-03-2019 / 10:51:33 / Claus Gittinger"
 !
 
 readStreamsDo:aBlock