Android Tutorial Android FTP tutorial

Status
Not open for further replies.

LucaMs

Expert
Licensed User
Longtime User
Hi all.

I'm doing some tests, using an emulator and my smartphone.

XAMPP-FILEZILLA on my pc.

User "home": C:\xampp\htdocs\AppTestUserDir

mFTPServerUserFolder = "/AppTestUserDir/"

Command: FTP.List(mFTPServerUserFolder)


Emulator (same using backslash \)
___________________________________________________________________________
Setting: mFTPServerUserFolder = "/"
(000001)30/10/2014 16:55:55 - (not logged in) (192.192.1.2)> 331 Password required for apptestuser
(000001)30/10/2014 16:55:55 - (not logged in) (192.192.1.2)> PASS **************
(000001)30/10/2014 16:55:55 - apptestuser (192.192.1.2)> 230 Logged on
(000001)30/10/2014 16:55:55 - apptestuser (192.192.1.2)> SYST
(000001)30/10/2014 16:55:55 - apptestuser (192.192.1.2)> 215 UNIX emulated by FileZilla
(000001)30/10/2014 16:55:55 - apptestuser (192.192.1.2)> PORT 10,0,2,2,252,192
(000001)30/10/2014 16:55:55 - apptestuser (192.192.1.2)> 200 Port command successful
(000001)30/10/2014 16:55:55 - apptestuser (192.192.1.2)> LIST /
(000001)30/10/2014 16:55:55 - apptestuser (192.192.1.2)> 150 Opening data channel for directory list.
(000001)30/10/2014 16:55:56 - apptestuser (192.192.1.2)> 425 Can't open data connection.
____________________________________________________________________________

Setting: mFTPServerUserFolder = "/AppTestUserDir/"
(000004)30/10/2014 17:05:23 - apptestuser (192.192.1.2)> LIST /AppTestUserDir/
(000004)30/10/2014 17:05:23 - apptestuser (192.192.1.2)> 550 Directory not found.
____________________________________________________________________________

C:\xampp\htdocs\AppTestUserDir contains one text file.



REAL DEVICE:
(RuntimeException) java.lang.RuntimeException: 530 User AppTestUser cannot log in.

Port 21 seems to be closed (tested from a site; the router admin console does not allow me to verify this)


Some help?


Thanks


[UPDATE] Using FTP.PassiveMode=True and the emulator the commands work.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I'm thinking that when I start a my b4J web server I need to open (and "link") a port (port forwarding) to allow a client to connect to the server ON MY PC.
Then che URL must be something like "xxx.xxx.xxx.xxx.pppp".

Since also my FTP server is on my pc, what should I do to allow a client to reach my server?


P.S. Opened, linked, NAT, port forwarding or whatelse is its name, 21 ---> my ftp server pc ip, nothing, the port seems to be still closed.


[SOLVED] Win7 Firewall was blocking the connection. Strangely, Comodo does not block it nor requests the permission, even though I have set this for each connection.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
[SOLVED] Win7 Firewall was blocking the connection. Strangely, Comodo does not block it nor requests the permission, even though I have set this for each connection.

Solved (almost) nothing!

Situation:

Emulator: all ok

Device: (RuntimeException) java.lang.RuntimeException: AppTestUser 530 User can not log in.

Same app, changing only the address of the server (local in the emulator, public IP address in the device).

Port 21 is open !!!
 

LucaMs

Expert
Licensed User
Longtime User




This morning, turning on the smartphone, everything works fine.

Apparently it needed a reboot.

Mah!
 

wonder

Expert
Licensed User
Longtime User
Hello Erel,

I have a security question, I hope you can help me.

I compiled code below and decompiled the generated apk via http://www.decompileandroid.com.
B4X:
Sub Process_Globals
    Dim FTP As FTP
End Sub
Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        FTP.Initialize("FTP", "ftp.example.com", 21, "user", "password")
    End If
End Sub


When I opened the JAVA file "main.java" with Wordpad, I found this:



As you can see, it's fairly easy to obtain a developer's FTP password. Is there a solution for this problem? How can I use FTP in B4A without making my password public?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
making my password public
It is not "public". You are doing illegal steps to reveal it.
You can ask the user for his ftp-login credentials and use his ftp then.
You should send files to your host in an other way. Using httputils and posting the file to an endpoint which gets the request and save the file.
 

wonder

Expert
Licensed User
Longtime User
You should send files to your host in an other way. Using httputils and posting the file to an endpoint which gets the request and save the file.
Thanks Manfred, I guess this covered in the HttpUtils tutorials, right? I'm not familiar with this method (yet).
All I want to do is upload game highscores to my server, as text files.

Thank you Erel, I will define the "password" in Process_Globals, repeat the compile/decompile test and see what comes up in the Java code.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel,
I'm trying to write a file upload iteration and I wish to track the failed uploads in order to retry the upload process.

So for each iteration a call UploadFile and I track (see code belove) the failed uploads saving the ServerPath within a list.
At the end of the process I'll iterate on the list (if any failed upload exists) in order to retry the file upload.

Is this possibile having only the ServerPath information ? In other words : Can I retreive the file name to upload within ServerPath ?

B4X:
Sub ftpClient_UploadCompleted (ServerPath As String, Success As Boolean)
    if errList.isInitialized = false then errList.Initialize
  
    If Success = False Then
        errList.Add (ServerPath)
        Log(LastException.Message)
    end if
end sub
 

hibrid0

Active Member
Licensed User
Longtime User
Error Uploading files.

B4X:
Sub Button1_Click
Log("FTP2 Inicializado "&FTP2.IsInitialized)

    FTP2.SendCommand("MKD", "/NEW")
        FTP2.UploadFile (File.DirRootExternal, "logo_.png", False, "/")
End Sub

In b4a not show anything, the command MKD is excuted, but the file is not uploaded.

I see in the log of Filezilla Server and say:

B4X:
(000010)26/06/2015 05:34:45 a.m. - jose (192.168.0.10)> PORT 192,168,0,10,169,36
(000010)26/06/2015 05:34:45 a.m. - jose (192.168.0.10)> 200 Port command successful
(000010)26/06/2015 05:34:45 a.m. - jose (192.168.0.10)> STOR /
(000010)26/06/2015 05:34:45 a.m. - jose (192.168.0.10)> 550 Filename invalid
(000010)26/06/2015 05:36:46 a.m. - jose (192.168.0.10)> 421 Connection timed out.
(000010)26/06/2015 05:36:46 a.m. - jose (192.168.0.10)> disconnected.

The command excuted by B4A is "STOR /", not sent anything.

I'm testing in Filezilla server, but in first time I test with my hosting and not work.
 

DonManfred

Expert
Licensed User
Longtime User
From the tutorial in Post #1

B4X:
FTP.UploadFile(File.DirRootExternal, "1.txt", True, "/somefolder/files/1.txt")

the last parameter must be PATH INCLUDING FILENAME. Not just a Path.

->

B4X:
FTP2.UploadFile (File.DirRootExternal, "logo_.png", False, "/logo_.png")
 

hibrid0

Active Member
Licensed User
Longtime User
Hi bro thanks for the quick answer.
I see it in the post #220, I test and work now I'm testing the real server :-D

Now I dont see is the progress in the log...
With the download I see the progress but in upload not.
 

Prosg

Active Member
Licensed User
Longtime User
Hello,
I have success to ftp a .mp4 files... but the file is corrupt

what can i do pls... (but i don't want to zip )
 

arnold steger

Member
Licensed User
Longtime User
How is the position for insert the comand "FTP.DownloadFile("Namen/", True, PfadDownload,name)"?
Download file is generated whit 0 kB

B4X:
Sub ButtonUploadList_Click
    FTP.List("Namen/")
End Sub

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
        ToastMessageShow(Folders,False)
        For i = 0 To Files.Length - 1
            Log(Files(i).Name & ", " & Files(i).Size & ", " & DateTime.Date(Files(i).Timestamp))
        Next
        ToastMessageShow(Files,False)
    End If
  
    If Success Then
    ToastMessageShow(ServerPath&Folders&" erfolgreich geladen",True)
    Else
    ToastMessageShow(ServerPath&" konnte nicht geladen werden",True)
    End If
  
End Sub
 
Last edited:

arnold steger

Member
Licensed User
Longtime User
i cannot see any download-command in your code
during the test of download i have insert in this methode.
B4X:
For i = 0To Files.Length - 1
Log(Files(i).Name & ", " & Files(i).Size & ", " & DateTime.Date(Files(i).Timestamp))
FTP.DownloadFile("Namen/", True, PfadDownload,name)
Next
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…