Android Question trying to use FTP but my code is in error

tsteward

Well-Known Member
Licensed User
Longtime User
I have created a new project and basically copied code from this site.
As much as I go over it and search here I can't see what I am doing wrong.
Line 42 is constantly underlined in red with this error.
Error occurred on line: 42
Dim tmp As Object = ftp.UploadFile(File.DirDefaultExternal, "some.jpg", False, "/LaraImages/uploads/")
Word: )

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim ftp As FTP
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    ftp.Initialize("ftp","xxxx.com",21,"xxxx_tony","xxxx")
    ftp.PassiveMode = True
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
    Dim tmp As Object = ftp.UploadFile(File.DirDefaultExternal, "some.jpg", False, "/LaraImages/uploads/")
    Wait For (tmp) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success Then
        MsgboxAsync( "Image successfully uploaded.", "Upload Success" )
    Else
        ToastMessageShow( "Image failed to upload!", True )
    End If
    
End Sub
 

TILogistic

Expert
Licensed User
Longtime User
Dim tmp As Object = ftp.UploadFile (File.DirDefaultExternal, "some.jpg", False, "/LaraImages/uploads/some.jpg")
Dim tmp As ResumableSub = ftp.UploadFile (File.DirDefaultExternal, "some.jpg", False, "/LaraImages/uploads/some.jpg")

see:
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Still underlined in red saying "Cannot assign void value."
It should be like this

B4X:
Sub Activity_Resume
    Try
        
        FTP.UploadFile(File.DirRootExternal, "1.wav", False, "11.wav")
    Catch
        Log(LastException)
    End Try

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    
    Try
    
        Dim s As String
        s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
        If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
        Log(s)
    
    Catch
        Log(LastException)
    End Try
    
End Sub

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

As you can see we are getting FTP result in a separate event FTP_UploadCompleted
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
ok thank you thats progress.
I am getting the following error and idea why?
(GaiException) android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
Yeah got most of the info out of filezilla.
New error now

(RuntimeException) java.lang.RuntimeException: Error uploading file.
550 /1089-2542.jpg: Permission denied
 
Upvote 0
Top