Platforms to show: All Mac Windows Linux Cross-Platform
/CURL/SFTP/CURLS sftp batch upload
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/SFTP/CURLS sftp batch upload
This example is the version from Wed, 3rd Jan 2023.
Project "CURLS sftp batch upload.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
DoUpload
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 Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control user Inherits TextField
ControlInstance user Inherits TextField
End Control
Control pass Inherits TextField
ControlInstance pass Inherits TextField
End Control
Control Bar Inherits ProgressBar
ControlInstance Bar Inherits ProgressBar
End Control
Control ProgressLabel Inherits Label
ControlInstance ProgressLabel Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
CurlMulti.Perform
End EventHandler
End Control
EventHandler Sub Open()
CurlMulti = new CURLMulti
CurlMulti.list = Listbox1
CurlMulti.ProgressLabel = ProgressLabel
CurlMulti.Bar = bar
CurlMulti.MaxTotalConnections = 10
End EventHandler
Private Sub DoUpload()
// get some data
dim lines() as string
for i as integer = 1 to 100000
lines.append "Just a little bit text. Have fun! "+str(i)
next
dim InputData as string = Join(lines, EndOfLine)
// init
ProgressLabel.Text = "Start..."
ProgressLabel.Visible = true
// create 100 files to upload and append them to queue
CurlMulti.TransfersDone = 0
dim count as integer = 100
for i as integer = 1 to count
dim e as integer
dim d as new UploadCURL
dim n as string = str(i, "000")
d.InputData = InputData
d.OptionURL = url.text + n + ".txt"
d.OptionUpload=true
d.optionverbose=true
d.CollectDebugMessages = True
d.OptionSSHAuthTypes = 2+8 // password, not public key
d.OptionUsername = user.Text
d.OptionPassword = pass.Text
d.ID = n
if CurlMulti.AddCURL(d) then
// ok
else
Break
end if
next
CurlMulti.TransfersTotal = count
bar.Value = 0
bar.Maximum = 100
bar.Visible = true
End Sub
Property CurlMulti As CURLMulti
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
Property ID As string
End Class
Class CURLMulti Inherits CURLSMultiMBS
EventHandler Sub TransferFinished(curl as CURLSMBS, result as Integer, RemainingFinishedTransfers as Integer)
dim DebugMessage as string = Curl.DebugMessages
// view in debugger
dim u as UploadCURL = UploadCURL(Curl)
dim m as string
Select case result
case CURLSMBS.kError_LOGIN_DENIED
m = "Wrong password."
case CURLSMBS.kError_UNSUPPORTED_PROTOCOL
m = "Protocol not implemented."
case CURLSMBS.kError_COULDNT_CONNECT
m = "Failed to connect."
case CURLSMBS.kError_FAILED_INIT
m = "Failed to initialize."
case CURLSMBS.kError_OK
m = "No error."
else
m = "Error "+str(result)
end select
List.addrow "Finished "+u.ID+": "+m
if result <> 0 then
Break
end if
TransfersDone = TransfersDone + 1
ProgressLabel.Text = str(TransfersDone)+" of "+str(TransfersTotal)
bar.Value = TransfersDone*100 / TransfersTotal
End EventHandler
EventHandler Sub TransfersFinished()
if TransfersDone = TransfersTotal then
TransfersTotal = -1
list.AddRow "All uploads done."
ProgressLabel.Text = "done"
bar.Visible = false
end if
End EventHandler
Property ProgressLabel As label
Property TransfersDone As Integer
Property TransfersTotal As Integer = -1
Property bar As ProgressBar
Property list As Listbox
End Class
End Project
See also:
The items on this page are in the following plugins: MBS CURL Plugin.