Skip to content

Commit d565e51

Browse files
committed
Mac feature complete
1 parent a07538d commit d565e51

16 files changed

Lines changed: 283 additions & 98 deletions

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.4dd
2+
*.4DIndx
3+
*.Match
4+
Logs
5+
Project/DerivedData
6+
*symbols.txt
7+
userPreferences.*
8+
Libraries/

Data/data.4DD

0 Bytes
Binary file not shown.

Data/data.journal

308 Bytes
Binary file not shown.
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{
22
"methods": {
33
"test": {
4-
"timeStamp": "2022-02-02T15:58:23.373Z"
4+
"timeStamp": "2022-02-07T11:21:35.129Z"
5+
},
6+
"Worker_ProgressBar": {
7+
"timeStamp": "2022-02-03T11:10:33.458Z"
58
},
69
"ErrorHandler": {
7-
"timeStamp": "2022-01-31T12:46:05.903Z"
10+
"timeStamp": "2022-02-03T10:50:18.425Z"
11+
},
12+
"ProgressCallback": {
13+
"timeStamp": "2022-02-07T10:10:51.936Z"
814
}
915
}
1016
}

Project/Sources/Classes/FileTransfer.4dm

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
Class 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
1113
Function 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+
4753
Function 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
5372
Function 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
148167
Function _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

181200
Function _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

Project/Sources/Classes/SystemWorkerProperties.4dm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
Class constructor($data : Object)
1+
Class constructor($data : Object; $callback : 4D:C1709.Function; $callbackID : Text)
22
This:C1470.encoding:="UTF-8"
3-
This:C1470.dataType:="text" // lowercase
3+
This:C1470.dataType:="text"
44
This:C1470.hideConsole:=True:C214
55
This:C1470.data:=$data
6-
7-
8-
6+
If (Count parameters:C259>1)
7+
This:C1470.callback:=$callback
8+
This:C1470.callbackID:=$callbackID
9+
ASSERT:C1129(Value type:C1509($callback)=Is object:K8:27; "Callback must be of type function")
10+
ASSERT:C1129(OB Instance of:C1731($callback; 4D:C1709.Function); "Callback must be of type function")
11+
ASSERT:C1129($callbackID#""; "Callback ID Method must not be empty")
12+
End if
913

1014
Function onResponse($systemworker : Object; $data : Object)
1115

16+
1217
Function onData($systemworker : Object; $data : Object)
1318
If (Value type:C1509($data.data)=38) // blob
1419

1520
Else
1621
If (String:C10($data.data)#"")
1722
This:C1470.data.text:=This:C1470.data.text+$data.data
23+
If (This:C1470.callback#Null:C1517)
24+
CALL WORKER:C1389("FileTransferProgress"; This:C1470.callback.source; This:C1470.callbackID; $data.data; 0)
25+
End if
1826
End if
1927
End if
2028

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
//%attributes = {}
22
// do nothing, just to fetch errors
3+
// used in cs.FileTransfer._runWorker()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//%attributes = {}
2+
#DECLARE($ID : Text; $message : Text; $value : Integer)
3+
// called from cs.FileTransfer if callback is set via .useCallback()
4+
5+
MESSAGE:C88($id+" - "+$message+" - "+String:C10($value))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//%attributes = {}
2+
// Cooperative Process to display Progress Bar
3+
4+
#DECLARE($job : Text; $info : Text; $value : Integer)
5+
6+
Case of
7+
: ($job="init")
8+
Progress New(
9+
10+
: ($job="close")
11+
End case

Project/Sources/Methods/test.4dm

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ $credentialspath:=Get 4D folder:C485(Database folder:K5:14)
55
$folder:=Folder:C1567($credentialspath; fk platform path:K87:2)
66
$credentialsfile:=$folder.parent.file("credentials.txt").getText()
77
$credentials:=JSON Parse:C1218($credentialsfile)
8+
If (False:C215)
9+
$credentials.url:="192.168.10.54:3421"
10+
End if
811

912
var $ftp : cs:C1710.FileTransfer
10-
$ftp:=cs:C1710.FileTransfer.new($credentials.url; $credentials.user; $credentials.pass; "ftp")
13+
$ftp:=cs:C1710.FileTransfer.new($credentials.url; $credentials.user; $credentials.pass; "sftp")
14+
$ftp.setCurlPath("/opt/homebrew/opt/curl/bin/curl")
1115
$ftp.setConnectTimeout(5)
1216

1317
If (False:C215)
@@ -17,7 +21,7 @@ If (False:C215)
1721
End if
1822
End if
1923

20-
If (False:C215)
24+
If (True:C214)
2125
$result:=$ftp.validate()
2226
If ($result.success)
2327

@@ -26,6 +30,8 @@ If (False:C215)
2630
End if
2731
End if
2832

33+
34+
2935
If (False:C215)
3036
$source:=System folder:C487(Desktop:K41:16)+"test2.txt"
3137
$source:=Convert path system to POSIX:C1106($source)
@@ -45,14 +51,16 @@ If (False:C215)
4551
End if
4652
End if
4753

48-
If (False:C215)
54+
If (True:C214)
4955
$result:=$ftp.getDirectoryListing("/")
5056
If ($result.success)
5157
$list:=$result.list
5258
End if
5359
End if
5460

5561
If (False:C215)
62+
//$ftp.useCallback(Formula(ProgressCallback); "ProgressCallback")
63+
5664
$source:="/test2.txt"
5765
$target:=System folder:C487(Desktop:K41:16)+"newtest2.txt"
5866
$target:=Convert path system to POSIX:C1106($target)
@@ -62,8 +70,13 @@ If (False:C215)
6270
End if
6371
End if
6472

65-
If (False:C215)
73+
If (True:C214)
74+
//$ftp.useCallback(Formula(ProgressCallback); "ProgressCallback")
6675
$source:="/test[1-3].txt"
76+
$source:="/large/4D.dmg"
77+
$source:="/large/FileZilla.bz2"
78+
$ftp.setRange("-100")
79+
6780
$target:=System folder:C487(Desktop:K41:16)+"neu"+Folder separator:K24:12
6881
$target:=Convert path system to POSIX:C1106($target)
6982
$result:=$ftp.download($source; $target)
@@ -95,13 +108,25 @@ If (False:C215)
95108
End if
96109
End if
97110

98-
If (True:C214)
111+
If (False:C215)
99112
$result:=$ftp.renameFile("/test3.txt"; "/test2.txt")
100113
If ($result.success)
101114
$list:=$result.list
102115
End if
103116
End if
104117

118+
119+
If (True:C214)
120+
$source:=System folder:C487(Desktop:K41:16)+"neu"+Folder separator:K24:12+"test[1-3].txt"
121+
$source:=Convert path system to POSIX:C1106($source)
122+
$ftp.setAutoCreateRemoteDirectory(True:C214)
123+
$ftp.setAutoCreateLocalDirectory(True:C214)
124+
$result:=$ftp.upload($source; "/meinfolder/"; True:C214)
125+
If ($result.success)
126+
$answer:=$result.data
127+
End if
128+
End if
129+
105130
/* test
106131
107132
test upload with 1-100].txt"

0 commit comments

Comments
 (0)