Platforms to show: All Mac Windows Linux Cross-Platform
/CURL/FTP/CURLS ftp file upload 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 file upload with thread
This example is the version from Tue, 16th Sep 2019.
Project "CURLS ftp file upload with thread.xojo_binary_project"
FileTypes
Filetype text
Filetype all
End FileTypes
Class Window1 Inherits Window
Control UploadButton Inherits PushButton
ControlInstance UploadButton Inherits PushButton
EventHandler Sub Action()
dim f as FolderItem = GetOpenFolderItem("all")
if f=nil then Return
dim p as new ProgressWindow
p.run url.Text, f
End EventHandler
End Control
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control URL Inherits TextField
ControlInstance URL Inherits TextField
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = ""
End MenuBar
Class App Inherits Application
End Class
Class UploadCURL Inherits CURLSMBS
EventHandler Function Progress(dltotal as Int64, dlnow as Int64, ultotal as Int64, ulnow as Int64, percent as double) As boolean
dim s as string
if ultotal=0 then
s="Uploading..."
else
dim d as Double = ulnow/ultotal
currentProgress = 100*d
s="Uploading "+Format(d,"-0%")+" "+Format(ulnow/1024.0,"0")+" of "+format(ultotal/1024.0,"0")+" KB"
end if
status = s
End EventHandler
EventHandler Function Read(count as integer) As string
Return stream.Read(count)
End EventHandler
EventHandler Function RestartRead() As boolean
stream.position=0
Return false // no error
End EventHandler
Property currentProgress As integer
Property status As string
Property stream As binaryStream
End Class
Class ProgressWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control bar Inherits ProgressBar
ControlInstance bar Inherits ProgressBar
End Control
Control fileName Inherits Label
ControlInstance fileName Inherits Label
End Control
Control status Inherits Label
ControlInstance status Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
me.Enabled=true
w.cancel
End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
if w<>Nil then
if w.done then
window1.listbox1.addrow "Result: "+str(w.result)
self.close
w.Cancel
w = nil
Return
end if
dim s as string = w.Status
bar.value = w.currentProgress
if s<>"" then
self.status.Text = s
window1.ListBox1.AddRow s
end if
end if
End EventHandler
End Control
Sub Run(URL as string, file as FolderItem)
fileName.Text = file.DisplayName
w=new workthread
w.file = file
w.url = url
w.run
End Sub
Property w As WorkThread
End Class
Class WorkThread Inherits Thread
EventHandler Sub Run()
dim b as BinaryStream = BinaryStream.Open(file)
curl = new UploadCURL
curl.stream = b
curl.OptionURL = URL
curl.OptionUpload = true
curl.YieldTime = true
curl.OptionInFileSizeLarge = b.Length
curl.OptionUsername = "test"
curl.OptionPassword = "xxxx"
result = curl.Perform
done = true
End EventHandler
Sub Cancel()
curl.Cancel = true
End Sub
Function CurrentProgress() As integer
Return curl.currentProgress
End Function
Function Status() As string
dim s as string = curl.status
curl.status = ""
Return s
End Function
Property URL As string
Property curl As UploadCURL
Property done As Boolean
Property file As FolderItem
Property result As integer
End Class
End Project
See also:
- /CURL/FTP/CURLS ftp directory browsing
- /CURL/FTP/CURLS ftp directory listing
- /CURL/FTP/CURLS ftp download to desktop with thread
- /CURL/FTP/CURLS ftp file delete
- /CURL/FTP/CURLS ftp file upload
- /CURL/FTP/CURLS ftp file upload direct
- /CURL/FTP/CURLS ftp file upload resume
- /CURL/FTP/CURLS ftp file uploads
- /CURL/FTP/CURLS ftp secure upload
- /CURL/FTP/CURLS ftp upload
The items on this page are in the following plugins: MBS CURL Plugin.