B4J Question How can I send a file to FTP and Email with b4j?

romario87027

Active Member
Licensed User
Longtime User
I tried with the library B4a Auto FTP but I get error.
B4X:
FTP.Initialize("",Me,"server","user","password",21,True,False)
FTP.UpLoadFile(File.DirApp,"/",FileName)
           
 FTP.Close
And I wanted to know if there is a library for sending emails. thanks
 

romario87027

Active Member
Licensed User
Longtime User
B4X:
Sub InviaFile(Filename As String)
FTP.Initialize("FTP", "server", 21, "user", "password")
          FTP.UploadFile(File.DirApp, Filename, True,Filename  )
           
           
            FTP.Close
End Sub
Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim s As String
    s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
    Log(s)
End Sub

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

I used the library Jnet, but does not send
 
Upvote 0

romario87027

Active Member
Licensed User
Longtime User
Erel Thank you for your response.
FTP Server was blocking my IP.
Now it works . I also added a progressbar
B4X:
Sub Class_Globals
    Dim pgBar As JavaObject
    Dim P As JavaObject = pgBar
    Dim prog As Double 
    Dim currentFileSize As Int

End Sub

Sub SendFile(FileName As String)

FTP.Initialize("FTP", "server", 21, "user", "password")
FileName= "tmp.txt"
          currentFileSize = (File.Size(File.DirApp, FileName))/1000
          FTP.UploadFile(File.DirApp,NomeFile, True, FileName)
           
           
            FTP.Close
End Sub
Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim s As String
   
   
    prog = Round(TotalUploaded / 1000) /currentFileSize
    P.RunMethod("setProgress",Array As Object(prog))
    s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
   
    Log(s)
End Sub

Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    Dim P As JavaObject = pgBar
    Dim prog As Double
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then Log(LastException.Message)
    prog = 1
    P.RunMethod("setProgress",Array As Object(prog))
End Sub
 
Upvote 0
Top