Android Tutorial Android FTP tutorial

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
No. FTP from the Net library is a client implementation.
 
Last edited:

juventino883

Member
Licensed User
Ok ok, i see, so if i want to create a specific folder in the server, the best option is to create a java server with b4j to implement it?, or what other solution could be factible?
 

Erel

Administrator
Staff member
Licensed User
I'm sorry I misread your previous question.

You can use this code to create a folder on the server:
B4X:
FTP.SendCommand("MKD", "/somefolder/newfolder")
Note that it is always better to start a new thread in the questions forum.
 

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
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
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
 

DonManfred

Expert
Licensed User
You should start a NEW thread in the questions forum for EVERY question you have.

Extending the tutorial-thread is the wrong place to ask.
 

rtek1000

Active Member
Licensed 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:
Uploaded 1KB
Uploaded 2KB
Uploaded 3KB
Uploaded 4KB
Uploaded 5KB
Uploaded 6KB
Uploaded 7KB
Uploaded 8KB
Uploaded 9KB
Uploaded 10KB
Uploaded 11KB
Uploaded 12KB
Uploaded 13KB
Uploaded 14KB
Uploaded 15KB
Uploaded 16KB
Uploaded 17KB
Uploaded 18KB
Uploaded 19KB
Uploaded 20KB
Uploaded 22KB
Uploaded 23KB
Uploaded 24KB
Uploaded 25KB
Uploaded 26KB
Uploaded 27KB
Uploaded 28KB
Uploaded 29KB
Uploaded 30KB
Uploaded 31KB
Uploaded 32KB
Uploaded 33KB
Uploaded 34KB
Uploaded 35KB
Uploaded 36KB
/sdcard/1.wav, Success=true
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

rtek1000

Active Member
Licensed 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
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 :p
 

red30

Active Member
Licensed 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?
 
Status
Not open for further replies.
Top