Platforms to show: All Mac Windows Linux Cross-Platform

/CURL/SFTP/CURLS sftp rename file batch


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 rename file batch

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

Project "CURLS sftp rename file batch.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Run 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 EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control ResultText Inherits Label
ControlInstance ResultText Inherits Label
End Control
Control StaticText11 Inherits Label
ControlInstance StaticText11 Inherits Label
End Control
Control Folder Inherits TextField
ControlInstance Folder Inherits TextField
End Control
Control StaticText111 Inherits Label
ControlInstance StaticText111 Inherits Label
End Control
Control StaticText1111 Inherits Label
ControlInstance StaticText1111 Inherits Label
End Control
Control OldText Inherits TextField
ControlInstance OldText Inherits TextField
End Control
Control FileNames Inherits TextArea
ControlInstance FileNames Inherits TextArea
End Control
Control NewText Inherits TextField
ControlInstance NewText Inherits TextField
End Control
Control StaticText11111 Inherits Label
ControlInstance StaticText11111 Inherits Label
End Control
Control Username Inherits TextField
ControlInstance Username Inherits TextField
End Control
Control StaticText1112 Inherits Label
ControlInstance StaticText1112 Inherits Label
End Control
Control StaticText11121 Inherits Label
ControlInstance StaticText11121 Inherits Label
End Control
Control Password Inherits TextField
ControlInstance Password Inherits TextField
End Control
Private Function ListFiles() As String() dim s as string dim e as integer dim d as new CURLSMBS d.CollectDebugMessages = true d.OptionDirListOnly = true d.CollectOutputData = true d.OptionVerbose = true d.OptionURL = ConvertEncoding(url.text+folder.Text, encodings.ISOLatin1) // our server uses ISOLatin1... d.OptionUsername = Username.Text d.OptionPassword = Password.Text e = d.Perform select case e case 0 // get output and show it. Maybe fix encoding s = d.OutputData if s.Encoding = nil then if encodings.UTF8.IsValidData(s) then s = DefineEncoding(s, encodings.UTF8) else s = DefineEncoding(s, encodings.ISOLatin1) end if end if s = ReplaceLineEndings(s, EndOfLine) editfield1.text=s ResultText.text="OK" dim items() as string = split(s, EndOfLine) if items.Ubound >= 0 and items(0) = "." then items.Remove 0 end if if items.Ubound >= 0 and items(0) = ".." then items.Remove 0 end if Return items else // show debug messages s = d.DebugMessages if s.Encoding = nil then if encodings.UTF8.IsValidData(s) then s = DefineEncoding(s, encodings.UTF8) else s = DefineEncoding(s, encodings.ISOLatin1) end if end if s = ReplaceLineEndings(s, EndOfLine) editfield1.text=s end select ResultText.text="Result: "+str(e)+" "+d.LasterrorMessage End Function
Private Sub Run() dim fileList() as string = ListFiles if fileList.Ubound = -1 then Return // nothing? dim commands() as string for each filename as string in fileList if filename = "" then continue if instr(filename, OldText.Text) > 0 then dim newName as string = folder.Text + Replace(filename, OldText.Text, NewText.Text) dim OldName as string = folder.Text + filename dim command as string command = "rename """+oldName+""" """+newName+"""" command = ConvertEncoding(command, encodings.ISOLatin1) // our server uses ISOLatin1... commands.append command end if next if commands.Ubound < 0 then ResultText.text="Nothing to do" MsgBox "Nothing to do" Return end if dim s as string dim e as integer dim d as new CURLSMBS d.SetOptionQuote commands d.CollectDebugMessages = true d.CollectOutputData = true d.OptionVerbose = true d.OptionURL = ConvertEncoding(url.text + folder.Text, encodings.ISOLatin1) // our server uses ISOLatin1... d.OptionUsername = Username.Text d.OptionPassword = Password.Text d.OptionDirListOnly = true e = d.Perform select case e case 0 // get output and show it. Maybe fix encoding s = d.OutputData if s.Encoding = nil then if encodings.UTF8.IsValidData(s) then s = DefineEncoding(s, encodings.UTF8) else s = DefineEncoding(s, encodings.ISOLatin1) end if end if s = ReplaceLineEndings(s, EndOfLine) editfield1.text=s else // show debug messages s = d.DebugMessages if s.Encoding = nil then if encodings.UTF8.IsValidData(s) then s = DefineEncoding(s, encodings.UTF8) else s = DefineEncoding(s, encodings.ISOLatin1) end if end if s = ReplaceLineEndings(s, EndOfLine) editfield1.text=s end select ResultText.text="Result: "+str(e)+" "+d.LasterrorMessage 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
End Project

See also:

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


The biggest plugin in space...