FTP upload to different Ftp folders using one button

Asmoro

Active Member
Licensed User
Longtime User
Hi all,

I'm trying to find an 'elegant' way to do this action.
But I'm stuck so far.
Maybe someone can see the problem that I have.

Okay, so here are the codes:

B4X:
Sub Process_Globals
   Dim result As String
   result = ""
   Dim FTP As FTP
   Dim Input1, Input2, SP As String
   Dim FP0, FP1  As String
   
   Dim Host, User, Password As String
   Host = "www.com"
   User = "1234"
   Password = "1234"
   Dim Port As Int

   Dim FPIndex As Int
   Dim FP(2) As String
   FP0 = "public_html/test1/"   
   FP1 = "public_html/test2/"
End Sub

B4X:
Sub Globals
   Dim LbAuto, LbMotor As Label
   Dim LbAutoInput, LbMotorInput  As Label
   Dim btSend As Button
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("preview.bal")
   FTPConnect   
   FTP.Initialize("FTP", Host, 21, User, Password)
End Sub

B4X:
Sub Activity_Resume
   
   LbAuto.Text = "" &  Selection       ------> Selection : values of a spinner(example: Alfa Romeo, BMW, etc)
      
End Sub

B4X:
Sub Activity_Pause (UserClosed As Boolean)
   LbAuto.Text = "" &  Selection
   FTP.Close   
End Sub

B4X:
Sub FTPConnect
   
End Sub

B4X:
Sub btSend_Click

   Input1 = LbAuto.Text
   Input2 = LbMotor.Text
   
   Dim Out As OutputStream
   Out = File.OpenOutput(File.DirRootExternal & "/Test/" , Input1 & Input2  &  ".jpg", False)  
   bmp.WriteToStream(Out, 100, "JPEG")
   Out.Close
   StartActivity("menu2")
   
   If Input1 = "BMW" Then           -------> This is what I came up with
      FP0 = True
        End If
                                    
   FTP.UploadFile(File.DirRootExternal & "/Test/", Input1 & Input2 &  ".jpg", False, FP(FPIndex) & Input1 & Input2 &  ".jpg") 
End Sub

B4X:
Sub   FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
                SP = FP(FPIndex) & Round(TotalUploaded / 1000) & "KB"     
                If Total > 0 Then SP = SP & " out of " & Round(Total / 1000) & "KB"
                Log(SP)
End Sub

B4X:
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
               Log(ServerPath & ", Success=" & Success)
               If Success = False Then Log(LastException.Message)
End Sub

So, by pushing btSend button, the image file will go to a ftp folder public_html/test or test2 depending on
the string of the value Input1/Input2.

Hope it's clear enough to understand the problem.

Thanks for now.
 
Last edited:

Asmoro

Active Member
Licensed User
Longtime User
Little update:

I manage to upload an image file to my FTP server,
but still not in the preferred folder.:sign0148:
The file came outside the serverpath instead.
So, it seems that the string codes don't work properly.

Another question for a solution:

Is it possible to assign multiple tags in a button Event Name in the Designer,
let say Tag: 0,1 or 0:1 or 0;1 or 0/1 etc..
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: it is better to post the code in a single section.

Each FTP account has a startup folder. The path should be related to this folder.

Is it possible to assign multiple tags in a button Event Name in the Designer,
let say Tag: 0,1 or 0:1 or 0;1 or 0/1 etc..
You are confusing EventName and Tag properties. These are two unrelated properties.
You can put whichever string you like in the tag property.
 
Upvote 0

Asmoro

Active Member
Licensed User
Longtime User
Hi Erel,

Yes, next time I'll follow your tip regarding posting the code.

And you're right, EventName and Tag are different things.
I didn't explain very well, I guess.

So multiple strings are allowed, but which characters I have to
use to seperate them, for example: 0,1 or 0:1 or 0.1 etc.
I only get errors instead.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…