Android Question Deleting file problem

Devv

Active Member
Licensed User
Longtime User
when i use the following code

B4X:
File.WriteString(File.DirInternal,"file.txt","hello")
    FTP.Initialize("FTP","ftp.mysite.com",21,"user","pass")
    FTP.UploadFile(File.DirInternal,"file.txt",False,"/htdocs/file.txt")
    FTP.Close
    Msgbox("done","")

every thing works file and i get the file


code 2:
B4X:
File.WriteString(File.DirInternal,"file.txt","hello")
    FTP.Initialize("FTP","ftp.mysite.com",21,"user","pass")
    FTP.UploadFile(File.DirInternal,"file.txt",False,"/htdocs/file.txt")
    FTP.Close
    File.Delete(File.DirInternal,"file.txt")
    Msgbox("done","")

when i use code 2 the file will never be uploaded and it will be deleted from the phone

any ideas why it is deleting the file without uploading it ?
 

DonManfred

Expert
Licensed User
Longtime User
UploadFile is ansynchronous sub or not? You should wait for the UploadCompleted event before you delete the file

B4X:
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then
      Log(LastException.Message)
    else
      ' Delete your file here...
    end if
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…