Android Question Upload FTP Files [Solved]

Jorgelcr

Active Member
Licensed User
Longtime User
Hello,

I am uploading files to my ftp command: FTP.UploadFile (DirmTMPFoto, ImageName to Send, False, rutaup) The files that I upload weigh very little about 60 kb. I have verified that when I am connected to a wifi network they upload perfectly, in few seconds, but when I am with data do not upload. I think before that it worked perfectly. Has someone happened to you? any solution?
 

DonManfred

Expert
Licensed User
Longtime User
but when I am with data
What do you mean with "but when i am with data"???
If you do not have access to the FTP server then the upload do not work.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I am connected to a wifi network
so you are using the IP of your internat network of the FTP-Server? 192.168.0.101 for ex.
If you need to connect from outside then you need to use the WAN-IP and your router must be configured to forward the request to your server running the ftp-server.
 
Upvote 0

Jorgelcr

Active Member
Licensed User
Longtime User
Hello,
What I mean is that with wifi connection works perfectly, but when the connection is via 3G, 4G, etc. it does not work
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What I mean is that with wifi connection works perfectly, but when the connection is via 3G, 4G, etc. it does not work
so you are using the IP of your internat network of the FTP-Server? 192.168.0.101 for ex.
If you need to connect from outside then you need to use the WAN-IP and your router must be configured to forward the request to your server running the ftp-server.
 
Upvote 0

Jorgelcr

Active Member
Licensed User
Longtime User
I do not understand, if for example I'm in a hotel, in a bar, my home connected with Wifi works correctly. But if at any of these sites I connect for 3g, 4g does not work. The initialization of ftp is always the same. Ftp.Initialize ("FTP", "ftp.xxxx.com", 21, "xxxx", "xxxx")
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I did understand!
BUT YOU(NOT ME) need to inform about networkstructures and the difference between a local networkand a mobile network

You can NOT connect to your local network using the ip from your local network when you are on Mobile data! You need to use the Online-IP from your router.
the router itself must be configured to forward port 21 to the machine running the FTP.
See your router configuration/documentation on how to do so.
 
Upvote 0

Jorgelcr

Active Member
Licensed User
Longtime User
I think I have not explained well, I do not want to connect to my local network. My FTP is on a remote server where I have my webpage hosted
 
Upvote 0

Jorgelcr

Active Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    Activity.LoadLayout("1")
    If FirstTime Then
    FTP.Initialize("FTP", "xxx.xx.com", 21, "xxx", "xx")
   
    End If
End Sub



   
Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
    Dim s As String
    s = "Downloaded " & Round(TotalDownloaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
    Log(s)
End Sub

Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then
         Log(LastException.Message)
    Else
        FTP.Close
    End If
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
    Dim ruta As String
    ruta="html/xx/xx/xxxx.jpg"
    FTP.DownloadFile(ruta, False, File.DirDefaultExternal, "foto.jpg")
End Sub
 
Upvote 0

Jorgelcr

Active Member
Licensed User
Longtime User
That is the problem that should work but it does not work.
If you want, I can access your private data.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Use the credentials from the pm i sent you

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim ftp As FTP
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    ftp.Initialize("FTP","basic4android.de",21,"f00xxxxxxxxxxx","set password from pn here")
    ftp.List("/")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log($"FTP_DownloadCompleted (${ServerPath}, ${Success})"$)
End Sub
Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    Log($"FTP_ListCompleted(${ServerPath},${Folders.Length},${Files.Length})"$)
    If Files.Length>0 Then
        For i = 0 To Files.Length-1
            Dim fle As FTPEntry = Files(i)
            ftp.DownloadFile("/"&fle.Name,False,File.DirRootExternal,fle.Name)
        Next
    End If
End Sub

This is working for me. It lists all files and download all files from this list.....
 
Upvote 0

Jorgelcr

Active Member
Licensed User
Longtime User
Hello,
Putting ftp.passivemode = true worked correctly !!!!
Many thanks. It was driving me crazy!!!

thanks Erel,DonManfred
 
Upvote 0
Top