Android Tutorial Android FTP tutorial

Status
Not open for further replies.

mojako

Member
Licensed User
If you are on a hosting web server you might not get
a file directory listing with this command:

FTP.List("/")


You should try using this instead:


FTP.List("./")


Worked for me, to get a directory listing for my home directory...
Yes, FTP.List("./") worked for me. The List is coming out.
but when I call ftp.UploadFile(File.DirDefaultExternal & "/", File.DirDefaultExternal & "/" & zipedfile, False, "./public_html/")
the log is : libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
what did I miss?
 

DonManfred

Expert
Licensed User
Longtime User
but when I call ftp.UploadFile(File.DirDefaultExternal & "/", File.DirDefaultExternal & "/" & zipedfile, False, "./public_html/")
The path is the path
your filename is a path and filename. Both together is a incorrect path-filename combination!

Go again over the ftp-tutorial (example) and find out what you did wrong
 

Valeriy Lakhtin

Member
Licensed User
Please help me DonManfred!
I have an FTP server, and from browser I can opens files and I can copie files to PC.
But I can not be copied to the phone all the files from a folder on my FTP. The error does not occur but there is no result. I have not found an example of how to get a list of files on FTP and then how to download all files from this list. I guess I'm not doing what that important action

B4X:
   ibFTP.Initialize("eventFTP", "ftp://ftp.informbyuro.kz", 21, "#####", "#####")
    yes=ibFTP.IsInitialized
    If yes=True Then
        Log("Hellow FTP!") ' this line OK
    End If

    Try
'    I want to download all the files from folders /ClikLike/Files but do not know. So I try to download one file, but there is no result
'    ibFTP.List("/")
    
    ibFTP.DownloadFile("/ClikLike/Files/g_zub.png", False, File.DirRootExternal, "/clicklike/Update/g_zub.png")

    Catch
    Log(LastException.Message)
    End Try
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Please help me DonManfred!
This is a community forum. Don´t limit your question to a single member!

So I try to download one file, but there is no result
you need to wait to the
B4X:
FTP_DownloadCompleted
event is raised...

Same principle for the List command... here you get the
B4X:
FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
event.

Go over the ftp documentation and the ftp-tutorial again i suggest
 

Valeriy Lakhtin

Member
Licensed User
I understand your point "This is a community forum. Don´t limit your question to a single member!"
So be sure to use
FTP_DownloadCompleted
And need wait when this event is raised then file downloaded. I checked on my the phone the file is very small and it is downloaded for 1-2 seconds
 

Valeriy Lakhtin

Member
Licensed User
I'm happy all worked aftere I changed the address.
"ftp://ftp.informbyuro.kz" to
"ftp.informbyuro.kz"


the following question, before downloading the need to clean the place or will rewrite files
 

rtek1000

Active Member
Licensed User
Longtime User
Hi,

The FTP server received a corrupted file

Is FTP only for text files?

I tried uploading it with another FTP client app downloaded in the play store and it worked correctly

Log:

B4X:
FTP.UploadFile(File.DirRootExternal & "/TTS2File/", filename, True, "/sdcard/" & filename)
B4X:
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

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

Attachments

  • Audio wav.zip
    61.8 KB · Views: 587

rtek1000

Active Member
Licensed User
Longtime User

Nice! Works!!

I changed from:
FTP.UploadFile (File.DirRootExternal & "/ TTS2File /", filename, True, "/ sdcard /" & filename)

To:
FTP.UploadFile (File.DirRootExternal & "/ TTS2File /", filename, False, "/ sdcard /" & filename)

Binary files are not loaded correctly in ASCII mode
 

red30

Well-Known Member
Licensed User
Longtime User
I have an FTP server. If I connect through Total Commander or cmd windows, everything works, but does not work through the FTP.Initialize? What could it be?
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        FTP.Initialize("FTP", "xxx.xxx.xxx.xxx", 21, "user", "password")
        If FTP.IsInitialized=True Then
            Log("Hellow FTP!") ' this line OK
        End If
    End If
    Activity.LoadLayout("Main")
End Sub
Sub Button1_Click
    FTP.List("/")
End Sub
Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
Log(ServerPath)
If Success = True Then
    Log("ok")
Else
    Log("no connection")
End If
End Sub
B4X:
** Activity (main) Create, isFirst = true **
Hellow FTP!
** Activity (main) Resume **
/
no connection
what am I doing wrong?
 

DonManfred

Expert
Licensed User
Longtime User
Status
Not open for further replies.