Platforms to show: All Mac Windows Linux Cross-Platform

/CURL/SFTP/CURLS SFTP Client


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 Client

This example is the version from Wed, 3rd Jan 2023.

Project "CURLS SFTP Client.xojo_binary_project"
FileTypes
Filetype text/html
Filetype all
End FileTypes
Class Window1 Inherits Window
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 StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control iServer Inherits TextField
ControlInstance iServer Inherits TextField
End Control
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control iPath Inherits TextField
ControlInstance iPath Inherits TextField
End Control
Control status Inherits Label
ControlInstance status Inherits Label
End Control
Control iUserName Inherits TextField
ControlInstance iUserName Inherits TextField
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() DoMultiUpload End EventHandler
End Control
Control iPassword Inherits TextField
ControlInstance iPassword Inherits TextField
End Control
Sub DoMultiUpload() dim folder as FolderItem=SelectFolder if folder=nil then Return Listbox1.DeleteAllRows status.text = "" dim d as new UploadsCURL FindFiles folder, d if UBound(d.files)=-1 then MsgBox "No files found in this folder!" Return end if d.YieldTime = true d.OptionFTPCreateMissingDirs=2 dim c as integer = UBound(d.files) for i as integer = 0 to c dim file as FolderItem = d.files(i) dim path as string = d.paths(i) dim b as BinaryStream = BinaryStream.Open(file) d.stream=b if iPath.text="" then d.OptionURL="sftp://"+iServer.text+"/"+path+file.name else d.OptionURL="sftp://"+iServer.text+"/"+iPath.text+"/"+path+file.name end if d.OptionSSHAuthTypes = 8 // keyboard // 2 // password d.OptionUsername = iUserName.Text d.OptionPassword = iPassword.Text d.OptionUpload=true d.OptionInFileSize=b.Length d.OptionUseSSL = d.kFTPSSL_CONTROL // Require SSL for the control connection or fail with CURLE_USE_SSL_FAILED. d.OptionSSLVerifyPeer=0 // don't verify peer d.OptionSSLVerifyHost=0 // ignore host name in verify 'd.OptionFreshConnect=false 'd.OptionPort=22 dim e as integer=d.Perform d.pos = d.pos + b.Length listbox1.addrow "Result: "+str(e) if e<>0 then Dim md as New MessageDialog //declare the MessageDialog object Dim mb as MessageDialogButton //for handling the result md.icon=MessageDialog.GraphicCaution //display warning icon md.ActionButton.Caption="Continue" md.CancelButton.Visible=True //show the Cancel button md.Message="We had an error with uploading this file: "+str(e)+". Should we try the next file?" mb=md.ShowModal //display the dialog Select Case mb //determine which button was pressed. Case md.ActionButton //user pressed Continue Case md.CancelButton //user pressed Cancel Return End select end if next End Sub
Private Sub DoUpload() dim f as FolderItem dim e as integer dim d as UploadCURL dim b as BinaryStream f=GetOpenFolderItem("all") if f=nil then Return Listbox1.DeleteAllRows status.text = "" b = BinaryStream.Open(f) d=new UploadCURL d.stream=b if iPath.text="" then d.OptionURL="sftp://"+iServer.text+"/"+f.name else d.OptionURL="sftp://"+iServer.text+"/"+iPath.text+"/"+f.name end if d.OptionUsername = iUserName.Text d.OptionPassword = iPassword.Text d.OptionSSHAuthTypes = 8 // keyboard // 2 // password d.YieldTime = true d.OptionUpload=true d.OptionFTPCreateMissingDirs=2 d.OptionInFileSize=b.Length d.OptionUseSSL = d.kFTPSSL_CONTROL // Require SSL for the control connection or fail with CURLE_USE_SSL_FAILED. d.OptionSSLVerifyPeer=0 // don't verify peer d.OptionSSLVerifyHost=0 // ignore host name in verify 'd.OptionFreshConnect=false 'd.OptionPort=22 e=d.Perform listbox1.addrow "Result: "+str(e) if e <> 0 then dim dd as string = d.DebugMessages // check for debug messages dd = ReplaceLineEndings(dd, EndOfLine) dim lines() as string = split(dd, EndOfLine) for each line as string in lines listbox1.AddRow line next end if End Sub
Sub FindFiles(folder as FolderItem, d as UploadsCURL, path as string="") dim c as integer = Folder.Count for i as integer = 1 to c dim file as FolderItem = Folder.TrueItem(i) if file.Visible then if file.Directory then FindFiles file, d, path+file.Name+"/" else d.files.Append file d.paths.Append path d.totalsize = d.totalsize + file.Length end if end if next End Sub
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 dim p as integer = 500*d if Window1.ProgressBar1.Value<>p then Window1.ProgressBar1.Value=p Window1.ProgressBar1.Refresh s="Uploading "+Format(d,"-0%")+" "+Format(ulnow/1024.0,"0")+" of "+format(ultotal/1024.0,"0")+" kB" if s<>Window1.status.text then Window1.status.text=s Window1.status.Refresh window1.listbox1.addrow s window1.listbox1.Refresh end if end if end if 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 stream As binaryStream
End Class
Class UploadsCURL 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 dim p as Double = pos + ulnow dim d as Double = p/totalsize dim mpercent as integer = 500*d if Window1.ProgressBar1.Value <> mpercent then Window1.ProgressBar1.Value = mpercent Window1.ProgressBar1.Refresh s="Uploading "+Format(d,"-0%")+" "+Format(p/1024.0,"0")+" of "+format(totalsize/1024.0,"0")+" kB" if s<>Window1.status.text then Window1.status.text=s Window1.status.Refresh window1.listbox1.addrow s window1.listbox1.Refresh end if end if 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 files() As FolderItem
Property paths() As string
Property pos As double
Property stream As binaryStream
Property totalsize As Double
End Class
End Project

See also:

The items on this page are in the following plugins: MBS CURL Plugin.


The biggest plugin in space...