Platforms to show: All Mac Windows Linux Cross-Platform
/CURL/FTP/CURLS ftp download to desktop with thread
Required plugins for this example: MBS CURL Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /CURL/FTP/CURLS ftp download to desktop with thread
This example is the version from Mon, 14th Jun 2015.
Project "CURLS ftp download to desktop with thread.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim url as string = Self.url.text
dim parts() as string = split(url, "/")
dim name as string = parts(UBound(parts))
dim DestinationFile as FolderItem = SpecialFolder.Desktop.Child(name)
DoDownload url, DestinationFile
End EventHandler
End Control
Control URL Inherits TextField
ControlInstance URL Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control ResultText Inherits Label
ControlInstance ResultText Inherits Label
End Control
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run()
Result = d.PerformMT
done = True
End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
if done then
me.mode = timer.ModeOff
d.CloseMTOutputFile
// show result
dim s as string = d.DebugMessages
s = ReplaceLineEndings(s, EndOfLine)
TextArea1.text = s
ResultText.text = "Result: "+str(result)
d = nil
else
if ResultText.text <> d.ProgressMessage then
ResultText.text = d.ProgressMessage
end if
end if
End EventHandler
End Control
Private Sub DoDownload(URL as string, dest as FolderItem)
d = new DownloadCURL
if not d.CreateMTOutputFile(dest) then
MsgBox "Failed to create file."
Return
end if
d.OptionURL = URL
// optional with credentials
'd.OptionUsername = "xxx"
'd.OptionPassword = "xxx"
// timeouts
'd.OptionConnectionTimeout = 10
'd.OptionTimeOut = 60
// more flags
d.OptionVerbose = true
d.OptionSSLVerifyHost = 0
d.OptionSSLVerifyPeer = 0
self.DestinationFile = dest
done = false
Thread1.run
timer1.mode = timer.ModeMultiple
End Sub
Property Private DestinationFile As FolderItem
Property Result As Integer
Property Private d As DownloadCURL
Property Private done As Boolean
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class DownloadCURL Inherits CURLSMBS
EventHandler Sub DebugMessage(infotype as integer, data as string, dataSize as Integer)
if infotype = kINFO_HEADER_IN or infotype = kINFO_HEADER_OUT or infotype = kINFO_TEXT then
if data.Encoding = nil then
data = DefineEncoding(data, encodings.ISOLatin1)
end if
DebugMessages = DebugMessages + data
end if
End EventHandler
EventHandler Function Progress(dltotal as double, dlnow as double, ultotal as double, ulnow as double) As boolean
if dltotal=0 then
ProgressMessage = "Downloading..."
else
ProgressMessage = "Downloading "+Format(dlnow/dltotal,"0%")
end if
Return false
End EventHandler
Property DebugMessages As string
Property ProgressMessage As string
End Class
End Project
See also:
- /CURL/FTP/CURLS ftp create or folder delete
- /CURL/FTP/CURLS ftp directory browsing
- /CURL/FTP/CURLS ftp directory listing
- /CURL/FTP/CURLS ftp directory listing with CURLFileInfoMBS
- /CURL/FTP/CURLS ftp download to desktop
- /CURL/FTP/CURLS ftp file delete
- /CURL/FTP/CURLS ftp file upload direct
- /CURL/FTP/CURLS ftp file upload resume
- /CURL/FTP/CURLS ftp file upload with progress
- /CURL/FTP/CURLS ftp secure upload
The items on this page are in the following plugins: MBS CURL Plugin.