Android Question Unable to download a file via FTP

beelze69

Active Member
Licensed User
Longtime User
Hi,

I have set up an FTP service with static IP. I have no issues in connecting to the Service via FTP commandline and pulling a file.. However, I am unable to do so using the program.

I am getting the following error message:

<BEGIN LOG>
Logger connected to: <MOBILE DEVICE ID>
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main~i:** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Sahibrao.txt, Success=false
libcore.io.ErrnoException: open failed: EACCES (Permission denied)
/
mysamplefile.txt, 44, 04/23/2018
mysamplefile1.txt, 47, 04/20/2018
mysamplefile.txt, Success=false
libcore.io.ErrnoException: open failed: EACCES (Permission denied)
/
mysamplefile.txt, 44, 04/23/2018
myfile1.txt. 47, 04/20/2018
** Activity (main) Pause, UserClosed = false **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
mysamplefile.txt, Success=false
org.apache.commons.net.ftp.FTPConnectionClosedException: FTP response 421 received. Server closed connection.
/
(FTPConnectionClosedException) org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
<END LOG>

<BEGIN CDOE>

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim FTP As FTP
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
FTP.Initialize( "FTP", "NNN.NN.NN.NNN", 21, "abcd", "abcd123")
FTP.PassiveMode=True
End If
Activity.LoadLayout("Main")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
Msgbox("Firing the click event for download","FTP EXAMPLE")
Msgbox(File.DirRootExternal,"TEST")
FTP.DownloadFile( "mysamplefile.txt", False, File.DirRootExternal, "mysamplefile.txt")
FTP.List ( "/")
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 Sub

'UPLOAD PROGRESS
'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
'

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

'LIST COMPLETED
Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
Log(ServerPath)
If Success = False Then
Log(LastException)
Else
For i = 0 To Folders.Length - 1
Log(Folders(i).Name)
Next
For i = 0 To Files.Length - 1
Log(Files(i).Name & ", " & Files(i).Size & ", " & DateTime.Date(Files(i).Timestamp))
Next
End If
End Sub

<END CODE>

Ps. help.. Thanks
 

DonManfred

Expert
Licensed User
Longtime User
1. Please use [CODE]code here...[/CODE] tags when posting code!
2. What is the targetsdk set to? Starting from Api 23 you need to use Runtimepermission for the Path file.DirRootExternal.
 
Last edited:
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
1. Please use [CODE]code here...[/CODE] tags when posting code!
2. What is the targetsdk set to? Starting from Api 23 you need to use Runtimepermission for the Path file.DirRootExternal.
Hi !
Sorry for the long delay. Was busy with other activities.

I have not set the TargetSDKVersion at all. In the log it shows me the listing of the files in the FTP server but I am unable to pull the file to my Mobile device...

Is there a problem with the code ? .. Ps. help...

Thanks
 
Upvote 0

beelze69

Active Member
Licensed User
Longtime User
Hi !

I have set the TargetSDKVersion to 19 in my manifest editor.. By the way, if I do not specify anything, what is the default value for the TargetSDKVersion ? ...
 
Upvote 0
Top