Android Tutorial Android FTP tutorial

Status
Not open for further replies.

DonManfred

Expert
Licensed User
Longtime User
My FTP_UploadCompleted event is never fired event if the upload is successful.
I have the FTP object on a code module... could that be the reason? Must the FTP object be on a service module?

Must be a Service or activity-code
 

luciano deri

Active Member
Licensed User
Longtime User
I ran your program and it seems to run fine.
It download the file and printed this message to the log:
Team/prestadores.txt, Success=true
I have a same problem. Download and upload are ok but the App don't execute
B4X:
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)
    FTP.Close
End Sub
Sub ftp_UploadCompleted (ServerPath As String, Success As Boolean)
    Msgbox(ServerPath & ", Success=" & Success,"")
    FTP.Close
End Sub
So i can't know when someting not is ok.
 

luciano deri

Active Member
Licensed User
Longtime User
Which app doesn't execute?
I call this sub pass the nomefile
B4X:
Sub ftp_download(nomefile As String)
    NomefileLocale = nomefile 
    NomefileRemoto = PthMultidataIN 
    If Not(NomefileRemoto.EndsWith("/")) Then
      NomefileRemoto = NomefileRemoto & "/" 
    End If  
    NomefileRemoto = NomefileRemoto & NomefileLocale 
    ProgressDialogShow("Download " & NomefileRemoto)
   
      ftp_imposta
    DoEvents
    FTP.DownloadFile(NomefileRemoto,True,Main.PthIO,NomefileLocale)
End Sub
Sub ftp_imposta
    DoEvents
    FTP.Initialize("FTP","WPOS001.mdata.locale",21,"tablet01","pwd01")
    FTP.PassiveMode=True
End Sub
The download is ok, but the app dont' enter in
FTP_DownloadCompleted ad
FTP_DownloadProgress
I thinked that app must execute this subs automatically. Is not so?
By, thanks
 

luciano deri

Active Member
Licensed User
Longtime User
You shouldn't initialize FTP multiple times. Just initialize it once.
ok, call ftp_imposta only in Activity_Create. But the problem persist, don't pass by ftp_UploadCompleted .
The file contain the report of FTP server where i upload file from tablet. I read in this forum that some other user had have this problem how had solve this?
 

Attachments

  • logFTPserver.txt
    4.8 KB · Views: 440

luciano deri

Active Member
Licensed User
Longtime User
The issue discussed in the other thread was related to very large files combined with slow connection (note that I wasn't able to reproduce that issue).

Please try to reproduce your issue in a small project and upload it.
Ok, thanks for your disponibility, next monday i return at work and i post a little example
 

Todd Carlton

Member
Licensed User
Longtime User
If within the same activity I need to download files from a server with two different user accounts, is there a way to initialize FTP a second time with different credentials?

First account's home = /home/user1
Second account's home is /home/user2

... and so I cannot use a single instance to download everything I need.

I have created an additional activity to start, download user 2's files and then finish. That works with a warning that FTP is already initialized. I am hoping to write the app free of warnings.

Thank you for any direction or instructions.

-OCS
 

JdV

Active Member
Licensed User
Longtime User
Hello

I'm using version 1.53 of the Net library and calling FTP.CloseNow doesn't seem to cancel the job - files are still downloaded in their entirety.

The test files I'm downloading aren't huge at around 8MB and 26MB each.

Regards

Joe
 

JdV

Active Member
Licensed User
Longtime User
Erel

Is there a plan to fix this?

I see that the attachment to post #123 addresses this issue but I think it was for uploads only. (I have tried the attachment for my situation and it didn't kill the downloads.)

Also, if 'total' usually returns "-1" in
FTP_DownloadProgress (ServerPath AsString, TotalDownloaded AsLong, Total AsLong) is that seen as a bug?

Regards

Joe
 
Last edited:

JdV

Active Member
Licensed User
Longtime User
Erel

Yes I have implemented the DownloadProgress event - I can see the TotalDownloaded value ticking up even after calling FTP.CloseNow several times.

Regards

Joe
 

JdV

Active Member
Licensed User
Longtime User
No it doesn't stop until after the complete file has downloaded.

Yes I'm using that version.

Regards

Joe
 

JdV

Active Member
Licensed User
Longtime User
I see what the issue is now!

In your example you name the variable, object and event 'FTP'. In my code I didn't.

If I follow your example exactly it works OK.

Thanks for the help.

Joe
 

atulindore

Member
Licensed User
Longtime User
Hi
I am using net lib to upload my file to ftp server.

===================================================
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        FTP.Initialize("FTP", "ftp.doamin.com", 21, "user", "pwd")
        FTP.PassiveMode = True
    End If
    Activity.LoadLayout("1")
End Sub

Sub BtnUpload_Click
        UploadBhavCopy
End Sub

Sub UploadBhavCopy
      FTP.UploadFile(File.DirDefaultExternal , "EQ081014.CSV", True, "/EQ081014.csv")
End sub

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)
    ToastMessageShow("File Uploaded",True)
    FTP.List("/")
    FTP.Close
    BtnUpload.Enabled = True
End Sub
===================================================
But file uploaded with 0 bytes ..


am I doing something wrong ?

My logs are showing correct uploading

Uploaded 256KB
Uploaded 257KB
Uploaded 258KB
Uploaded 259KB
Uploaded 260KB
Uploaded 261KB
Uploaded 262KB
Uploaded 263KB
Uploaded 264KB

Pls suggest ..

Thanks

Its working now ...
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…