Skip to content

Commit 3e89ab1

Browse files
committed
update for HTTP(s)
1 parent 758e924 commit 3e89ab1

5 files changed

Lines changed: 42 additions & 5 deletions

File tree

File renamed without changes.

Project/Sources/Classes/FileTransfer.4dm renamed to Project/Sources/Classes/FileTransfer_curl.4dm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Class constructor($hostname : Text; $username : Text; $password : Text; $protoco
33
If ($protocol="")
44
$protocol:="ftp-ftps"
55
End if
6-
$col:=New collection:C1472("ftp"; "ftps"; "sftp"; "ftp-ftps")
6+
$col:=New collection:C1472("ftp"; "ftps"; "sftp"; "ftp-ftps"; "https"; "http")
77
ASSERT:C1129($col.indexOf($protocol)>=0; "Unsupported protocol")
88
This:C1470._host:=$hostname
99
This:C1470._user:=$username
@@ -272,6 +272,13 @@ Function _buildURL()->$url : Text
272272
$url+=This:C1470._user+":"+This:C1470._password+"@"
273273
End if
274274
$url+=This:C1470._host
275+
276+
: ((This:C1470._protocol="https") | (This:C1470._protocol="http"))
277+
$url:=This:C1470._protocol+"://"
278+
If (This:C1470._user#"")
279+
$url+=This:C1470._user+":"+This:C1470._password+"@"
280+
End if
281+
$url+=This:C1470._host
275282
Else
276283
ASSERT:C1129(True:C214; "unsupported protocol")
277284
End case

Project/Sources/Methods/test.4dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ If (True:C214)
99
$credentials.url:="192.168.10.54:3421"
1010
End if
1111

12-
var $ftp : cs:C1710.FileTransfer
13-
$ftp:=cs:C1710.FileTransfer.new($credentials.url; $credentials.user; $credentials.pass; "ftp")
12+
var $ftp : cs:C1710.FileTransfer_curl
13+
$ftp:=cs:C1710.FileTransfer_curl.new($credentials.url; $credentials.user; $credentials.pass; "ftp")
1414
//$ftp.setCurlPath("/opt/homebrew/opt/curl/bin/curl")
1515
//$ftp.setCurlPath("C:\\Users\\thomas.DE\\Documents\\4D\\Komponenten\\curl.exe")
1616
$ftp.setConnectTimeout(5)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//%attributes = {}
2+
var $ftp : cs:C1710.FileTransfer_curl
3+
$ftp:=cs:C1710.FileTransfer_curl.new("www.4d.com"; ""; ""; "https")
4+
$ftp.setConnectTimeout(5)
5+
6+
$source:="/de"
7+
$target:=System folder:C487(Desktop:K41:16)+"newtest2.txt"
8+
$target:=Convert path system to POSIX:C1106($target)
9+
$ftp.setCurlPrefix("--location") // follow 301 or 302
10+
$result:=$ftp.download($source; $target)
11+
If ($result.success)
12+
$answer:=$result.data
13+
End if
14+

Readme.MD

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ This class allows easy usage of cURL to transfer files to and from FTP and FTPS
1919
# Usage example
2020

2121
```4D
22-
var $ftp : cs.FileTransfer
23-
$ftp:=cs.FileTransfer.new("ftp.4d.com"; "username"; "password"; "ftps")
22+
var $ftp : cs.FileTransfer_curl
23+
$ftp:=cs.FileTransfer_curl.new("ftp.4d.com"; "username"; "password"; "ftps")
2424
$source:="/product/4D.dmg"
2525
$target:=Convert path system to POSIX(System folder(Desktop))
2626
$result:=$ftp.download($source; $target)
@@ -53,4 +53,20 @@ Copy this 2-4 files into your project, done.
5353
See Class documentation (in 4D use Explorer/Documentation)
5454
[Documentation](https://github.com/ThomasMaul/FileTransfer_Class/blob/main/Documentation/Classes/FileTransfer.md)
5555

56+
# HTTP/HTTPS
57+
cURL is also a great tool for HTTP(s) communication, to upload or download files.
58+
While the class is mainly written for (s)FTP(s), it can also be use for HTTP(s).
59+
Read cURL documentation to find about feature set, such as to reuse cookies or follow redirects.
5660

61+
## Usage example for http
62+
```4D
63+
var $ftp : cs.FileTransfer_curl
64+
$ftp:=cs.FileTransfer_curl.new("www.4d.com"; ""; ""; "https")
65+
$ftp.setConnectTimeout(5)
66+
67+
$source:="/de"
68+
$target:=System folder(Desktop)+"newtest2.html"
69+
$target:=Convert path system to POSIX($target)
70+
$ftp.setCurlPrefix("--location") // follow 301 or 302
71+
$result:=$ftp.download($source; $target)
72+
```

0 commit comments

Comments
 (0)