Android Question NET library v1.81 - FTP does it still work? [B4A]

mash4aa

Member
Licensed User
Longtime User
Hi
I have a question whether the NET library currently works. I have a strange situation - I tried to connect to 3 different FTP servers and none of them downloaded the file. I don't know if I'm doing everything right. Here is my sample code:

code:
Sub Process_Globals
    Dim FTP As FTP
    'Dim rp As RuntimePermissions
End Sub

Sub Globals
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")   
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)
    End If
End Sub

Sub Button1_Click
    FTP.Initialize("FTP", "ftp.cpc.ncep.noaa.gov", 21, "anonymous", "")
    Log("Results:" & FTP.IsInitialized)
    FTP.PassiveMode=True
    If FTP.IsInitialized Then
        FTP.DownloadFile("/wd52dg/data/indices/tele_index_nh", True, File.DirRootExternal, "111.txt")
       'FTP.DownloadFile("wd52dg/data/indices/tele_index_nh", True, File.DirRootExternal, "111.txt")
    End If
End Sub


You can connect normally using WinSCP

Manifest file:

manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
 

Attachments

  • ftp_new.zip
    9.1 KB · Views: 107

mash4aa

Member
Licensed User
Longtime User
I changed it to "wait for" but nothing still happens. there is nothing in the logs because nothing is happening. I'm sending a new code.
 

Attachments

  • ftp_new_wait.zip
    9.1 KB · Views: 121
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
File.DirRootExternal
whenever you see this path you immediately know it is broken.

You do not have access to this folder with targetsdk 33

 
Upvote 1

DonManfred

Expert
Licensed User
Longtime User
change this line
B4X:
    Dim sf As Object = FTP.DownloadFile("wd52dg/data/indices/tele_index_nh", True, File.DirRootExternal, "111.txt")

to this one
B4X:
    Dim sf As Object = FTP.DownloadFile("wd52dg/data/indices/tele_index.nh", True, File.DirInternal, "111.txt")

1. Note that you were using a WRONG filename (file does not exists!). This is the base of your problem with getting
Error download file
2. Note that i replaced the destinationpath

Logger verbunden mit: samsung SM-G973F
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
file was downloaded successfully
 
Upvote 0

mash4aa

Member
Licensed User
Longtime User
Can you send me a zip with this improved project? I changed the lines to
B4X:
Dim sf As Object = FTP.DownloadFile("wd52dg/data/indices/tele_index.nh", True, File.DirInternal, "111.txt")
but something still doesn't make sense to me
I'll see what manifest file you have :)
 
Upvote 0

mash4aa

Member
Licensed User
Longtime User
The problem turned out to be the WiFi connection. I enabled the hotspot from Windows 11 to transfer the project in b4a and when connecting to FTP something got stuck and nothing happened. After switching to mobile data, it downloaded the file. Thank you.
 
Upvote 0
Top