Android Question How to upload a file to a domain that I own?

ClarkJay

Member
Licensed User
Longtime User
Hello,

I am a newbie here with regards to B4A. I appreciate any help or any info with regards to this:

A file would be made by an android app and I want to that file to be uploaded automatically to one of the specified folder on a webhost administered by me and would serve as a repository of those files.

Supposed "temp.txt" would be uploaded to a folder "http://www.anysite.com/files/".

What code and what library can be used by that?

Any help would be gladly received...
 

strat

Active Member
Licensed User
Longtime User
You neeed NET Library. Using this code you can upload and download files to your own domain.


B4X:
Sub Globals
    Dim filename as String
End Sub

Sub Process_Globals
    Dim ftp1 As FTP
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ftp1.Initialize("ftp1", "http://www.anysite.com", port number, "username", "password")
End Sub

Sub downloadfile
    ftp1.DownloadFile("/files/"&filename, False, File.DirRootExternal,filename)
End Sub

Sub ftp1_DownloadCompleted (ServerPath As String, Success As Boolean)
    If Success = True Then
        'Do something
    Else
        'Do something
    End If
End Sub

Sub ftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    If Success = False Then
        'Do something
    Else
        'Do something
    End If
End Sub

Sub uploadfile
    ftp1.UploadFile(File.Dirrootexternal,filename, True, "/files/"&filename)
End Sub
 
Upvote 0

ClarkJay

Member
Licensed User
Longtime User


I can't seem to make this work, even if I use a wrong FTP password, it would still show as initialized and download/upload successful.
 
Upvote 0

ClarkJay

Member
Licensed User
Longtime User
By the way, is there no problem when there are literally hundreds of connections with different IPs simultaneously uploading at the same time with different filenames. I mean would the http server allow these connections by queue or at same time? Just wondering?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…