11Class constructor ($hostname : Text; $username : Text; $password : Text; $protocoll : Text)
22 ASSERT:C1129 ($hostname # "" ; "Hostname must not be empty" )
3- $col := New collection:C1472 ("ftp" ; "ftps" )
3+ $col := New collection:C1472 ("ftp" ; "ftps" ; "sftp" )
44 ASSERT:C1129 ($col .indexOf ($protocoll )>= 0 ; "Unsupported protocoll" )
55 This:C1470 ._host := $hostname
66 This:C1470 ._user := $username
77 This:C1470 ._password := $password
88 This:C1470 ._protocoll := $protocoll
99 This:C1470 .onData := New object:C1471 ("text" ; "" )
10+ This:C1470 ._noProgress := True:C214
1011
12+ // MARK: Settings
1113Function validate ()- > $success : Object
1214 $url := This:C1470 ._buildURL ()
1315 $url + = "/"
@@ -44,12 +46,29 @@ Function setActiveMode($active : Boolean; $IP : Text)
4446 This:C1470 ._ActiveModeIP := $IP
4547 End if
4648
49+ Function setRange ($range : Text)
50+ // 0-99 or -500 (last 500) , 500- (starting with 500 till end)
51+ This:C1470 ._range := $range
52+
4753Function setCurlPrefix ($prefix : Text)
4854 // allows to set any parameters directly after curl
4955 This:C1470 ._prefix := $prefix
5056
57+ Function setCurlPath ($path : Text)
58+ This:C1470 ._curlPath := $path
59+
60+ Function enableProgressData ($enable : Boolean)
61+ This:C1470 ._noProgress := Not:C34 ($enable )
5162
63+ Function useCallback ($callback : 4D:C1709 .Function ; $ID : Text)
64+ ASSERT:C1129 (Value type:C1509 ($callback )= Is object:K8:27 ; "Callback must be of type function" )
65+ ASSERT:C1129 (OB Instance of:C1731 ($callback ; 4D:C1709 .Function ); "Callback must be of type function" )
66+ ASSERT:C1129 ($ID # "" ; "Callback ID Method must not be empty" )
67+ This:C1470 ._Callback := $callback
68+ This:C1470 ._CallbackID := $ID
69+ This:C1470 ._noProgress := False:C215
5270
71+ // MARK: FileTransfer
5372Function upload ($sourcepath : Text; $targetpath : Text; $append : Boolean)- > $success : Object
5473 // $sourcepath just file name for local directory, else full path in POSIX syntax
5574 // targetpath is remote path. / for same name as local file in default dir, else /dir/ or /dir/newname.txt
@@ -82,12 +101,12 @@ target needs to be folder, ending with /
82101 ASSERT:C1129 ($targetpath # "" ; "target path must not be empty" )
83102 $url := This:C1470 ._buildURL ()
84103 If ((This:C1470 ._AutoCreateLocalDir # Null:C1517) && (This:C1470 ._AutoCreateLocalDir ))
85- $url := "--create-dirs " + $url
104+ $url := " --create-dirs " + $url
86105 End if
87106 If ($targetpath= "@/ ")
88107 $url := " --output-dir " + $targetpath + " --remote-name-all " + $url + $sourcepath
89108 Else
90- $url := " -o " + $targetpath + $url + $sourcepath
109+ $url := " -o " + $targetpath + " " + $url + $sourcepath
91110 End if
92111 $success := This:C1470 ._runWorker ($url )
93112
@@ -144,7 +163,7 @@ Function renameFile($sourcepath : Text; $targetpath : Text)->$success : Object
144163 End if
145164
146165
147-
166+ // MARK: Internal helper calls
148167Function _parseDirListing ($success : Object)
149168 $col := Split string:C1554 ($success .data ; Char:C90 (10 ); sk ignore empty strings:K86:1 )
150169 $success .list := New collection:C1472
@@ -179,31 +198,58 @@ Function _parseDirListing($success : Object)
179198 End for each
180199
181200Function _buildURL ()- > $url : Text
182- $url := "ftp://"
183- If (This:C1470 ._user # "")
184- $url + = This:C1470 ._user + ":" + This:C1470 ._password + "@"
185- End if
186- $url + = This:C1470 ._host
187- If (This:C1470 ._protocoll = "ftps")
188- $url := "-ssl " + $url
201+ Case of
202+ : ((This:C1470 ._protocoll = "ftps") | (This:C1470 ._protocoll = "ftp"))
203+ $url := "ftp://"
204+ If (This:C1470 ._user # "")
205+ $url + = This:C1470 ._user + ":" + This:C1470 ._password + "@"
206+ End if
207+ $url + = This:C1470 ._host
208+ If (This:C1470 ._protocoll = "ftps")
209+ $url := "-ssl " + $url
210+ End if
211+ : (This:C1470 ._protocoll = "sftp")
212+ $url := "sftp://"
213+ If (This:C1470 ._user # "")
214+ $url + = This:C1470 ._user + ":" + This:C1470 ._password + "@"
215+ End if
216+ $url + = This:C1470 ._host
217+ Else
218+ ASSERT:C1129 (True:C214 ; "unsupported protocoll" )
219+ End case
220+
221+
222+ Function _runWorker ($para : Text)- > $result : Object
223+ If (This:C1470 ._Callback # Null:C1517)
224+ $workerpara := cs:C1710 .SystemWorkerProperties .new (This:C1470 .onData; This:C1470 ._Callback; This:C1470 ._CallbackID)
225+ Else
226+ $workerpara := cs:C1710 .SystemWorkerProperties .new (This:C1470 .onData)
189227 End if
190228
191- Function _runWorker ($para : Text; $async : Boolean)- > $result : Object
192- $workerpara := cs:C1710 .SystemWorkerProperties .new (This:C1470 .onData)
229+ If ((This:C1470 ._curlPath ) && (This:C1470 ._curlPath # ""))
230+ $path := This:C1470 ._curlPath
231+ Else
232+ $path := "curl"
233+ End if
193234
194- $path := "curl"
195- If (This:C1470 ._prefix # Null:C1517)
196- $path + = (" "+ This:C1470 ._prefix )
235+ If ((This:C1470 ._noProgress # Null:C1517) && (This:C1470 ._noProgress ))
236+ $path + = " --no-progress-meter"
197237 End if
198238 If (This:C1470 ._connectTimeout # Null:C1517)
199239 $path + = " --connect-timeout " + String:C10 (This:C1470 ._connectTimeout )
200240 End if
201241 If (This:C1470 ._maxTime # Null:C1517)
202242 $path + = " --max-time " + String:C10 (This:C1470 ._maxTime )
203243 End if
244+ If (This:C1470 ._range # Null:C1517)
245+ $path + = " --range " + This:C1470 ._range
246+ End if
204247 If ((This:C1470 ._ActiveMode # Null:C1517) && (This:C1470 ._ActiveMode )) // default passive
205248 $path + = " --ftp-port " + This:C1470 .ActiveModeIP
206249 End if
250+ If (This:C1470 ._prefix # Null:C1517)
251+ $path + = (" "+ This:C1470 ._prefix )
252+ End if
207253
208254 $command := $path + " " + $para
209255 var $worker : 4D:C1709 .SystemWorker
@@ -233,4 +279,5 @@ Function _runWorker($para : Text; $async : Boolean)->$result : Object
233279 ON ERR CALL:C155 ($old )
234280
235281
282+
236283
0 commit comments