Platforms to show: All Mac Windows Linux Cross-Platform
/CURL/SFTP/CURLS sftp batch download
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 download
This example is the version from Wed, 3rd Jan 2023.
Project "CURLS sftp batch download.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()
DownloadListing url.Text
End EventHandler
End Control
Control LogList Inherits ListBox
ControlInstance LogList 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 = LogList
CurlMulti.ProgressLabel = ProgressLabel
CurlMulti.Bar = bar
CurlMulti.MaxTotalConnections = 10
End EventHandler
Sub DownloadFile(name as string, folderURL as string)
// load a file
dim e as integer
dim d as new CURLSMBS
d.OptionURL = FolderURL + name
d.OptionDirListOnly = True
d.OptionSSHAuthTypes = 2+8 // password, not public key
d.OptionUsername = user.Text
d.OptionPassword = pass.Text
d.CollectOutputData = false
d.CollectDebugMessages = true
d.CollectHeaders = true
dim file as FolderItem = SpecialFolder.Desktop.Child(name)
if not d.CreateMTOutputFile(file) then
MsgBox "Failed to create file: "+name
return
end if
if CurlMulti.AddCURL(d) then
// ok
else
Break
end if
CurlMulti.TransfersTotal = CurlMulti.TransfersTotal + 1
bar.Value = CurlMulti.TransfersDone
bar.Maximum = CurlMulti.TransfersTotal
bar.Visible = true
ProgressLabel.Text = "Load file "+name
'LogList.AddRow str(CurlMulti.TransfersDone)+" of "+str(CurlMulti.TransfersTotal)
End Sub
Sub DownloadListing(FolderURL as string)
// list files in folder
ProgressLabel.Text = "Start..."
ProgressLabel.Visible = true
CurlMulti.TransfersDone = 0
CurlMulti.TransfersTotal = 1
dim e as integer
dim d as new CURLSMBS
d.OptionURL = FolderURL
d.OptionDirListOnly = True
d.OptionSSHAuthTypes = 2+8 // password, not public key
d.OptionUsername = user.Text
d.OptionPassword = pass.Text
d.CollectOutputData = true
d.CollectDebugMessages = true
d.CollectHeaders = true
if CurlMulti.AddCURL(d) then
// ok
else
Break
end if
bar.Value = CurlMulti.TransfersDone
bar.Maximum = CurlMulti.TransfersTotal
bar.Visible = true
'LogList.AddRow str(CurlMulti.TransfersDone)+" of "+str(CurlMulti.TransfersTotal)
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 CURLMulti Inherits CURLSMultiMBS
EventHandler Sub TransferFinished(curl as CURLSMBS, result as Integer, RemainingFinishedTransfers as Integer)
dim DebugMessage as string = Curl.DebugMessages
TransfersDone = TransfersDone + 1
// view in debugger
dim u as CURLSMBS = 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 "+curl.OptionURL
if result <> 0 then
Break
end if
if curl.OptionDirListOnly then
// got list of files
dim list as string = curl.OutputData
list = ReplaceLineEndings(list, EndOfLine)
dim files() as string = split(list, EndOfLine)
// download all
for each filename as string in files
if filename = "" then continue
if filename.left(1) = "." then continue // skip folders or invisible files
// start a download
MainWindow.DownloadFile filename, curl.OptionURL
next
else
// file loaded
ProgressLabel.Text = str(TransfersDone)+" of "+str(TransfersTotal)
bar.Value = TransfersDone * 100 / TransfersTotal
end if
'list.addrow str(self.TransfersDone)+" of "+str(self.TransfersTotal)
if TransfersDone = TransfersTotal then
TransfersTotal = -1
list.AddRow "All downloads 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.