Hi community,
I am struggling one week already with the problem, how to handle the end of FTP download process.
I have code like this, where I just download file and read first line of it.
Now, when function
is called, code immediately goes ahead and executes next line
and consequently next line
, where it crashes with error message: java.io.FileNotFoundException: ... open failed: ENOENT (No such file or directory). It seems to me, that just after that, the requested file is downloaded and available for reading...
Please, how can I force the code to wait till the file is downloaded and just afterwards to run ahead?
BTW, another problem, variable "del" is True after executing File.Delete(storage, downloadedFile) and deleting downloadedFile, but, the file is still in storage directory... Any ideas why?
Thank you
I am struggling one week already with the problem, how to handle the end of FTP download process.
I have code like this, where I just download file and read first line of it.
B4X:
Sub Activity_Create(FirstTime As Boolean)
storage = File.DirRootExternal
FTP.Initialize("FTP", FTPServer, 21, "UserName", "Password")
TheDownloadFunction
End Sub
Sub TheDownloadFunction
Dim content as String
Dim del as Boolean
{some code...}
ProgressDialogShow("Downloading file...")
DownloadSelectedFile
txtReader.Initialize(File.OpenInput(storage, downloadedFile))
content = txtReader.ReadLine
txtReader.Close
del = File.Delete(storage, downloadedFile)
End Sub
Sub DownloadSelectedFile()
FTP.DownloadFile(ftpFolder & downloadedFile, False, storage, downloadedFile)
End Sub
Sub FTP_DownloadProgress (ServerPath As String, TotalDownloaded As Long, Total As Long)
Dim str As String
str = "Downloaded " & Round(TotalDownloaded / 1000) & " kB"
If Total > 0 Then str = str & " out of " & Round(Total / 1000) & "KB"
Log(str)
End Sub
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
ProgressDialogHide
End Sub
Now, when function
B4X:
DownloadSelectedFile
B4X:
txtReader.Initialize(File.OpenInput(storage, downloadedFile))
B4X:
content = txtReader.ReadLine
Please, how can I force the code to wait till the file is downloaded and just afterwards to run ahead?
BTW, another problem, variable "del" is True after executing File.Delete(storage, downloadedFile) and deleting downloadedFile, but, the file is still in storage directory... Any ideas why?
Thank you
Last edited: