1. You are closing FTP after the first file.
2. You can use For Each, which is more elegant.
B4X:
FTP.PassiveMode = True
For Each pdfFile In pdfList
If pdfFiles.EndsWith(".pdf") Then
Dim sf As Object = FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ": "& Success)
End If
Next
FTP.Close
I'm now experiencing a problem that I can't seem to solve...
When I run my app without Wait for... it copies all files to the FTP
Without Wait For...:
Dim pdfList As List
Dim i As Int
pdfList.Initialize
pdfList=File.ListFiles(File.DirInternal)
For i=0 To pdfList.Size-1
pdfFiles=pdfList.Get(i)
If pdfFiles.EndsWith(".pdf")
FTP.PassiveMode = True
FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
FTP.Close
End If
Next
However, when I include Wait for... only the first file is copied
Including Wait For...:
Dim pdfList As List
Dim i As Int
pdfList.Initialize
pdfList=File.ListFiles(File.DirInternal)
For i=0 To pdfList.Size-1
pdfFiles=pdfList.Get(i)
If pdfFiles.EndsWith(".pdf") Then
FTP.PassiveMode = True
Dim sf As Object = FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
FTP.Close
End If
Next
What am I doing wrong...?
Events...
Events:
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 = True Then
Log("COPIED")
Else
Log(LastException.Message)
End If
End Sub
1. You are closing FTP after the first file.
2. You can use For Each, which is more elegant.
B4X:
FTP.PassiveMode = True
For Each pdfFile In pdfList
If pdfFiles.EndsWith(".pdf") Then
Dim sf As Object = FTP.UploadFile(File.DirInternal, pdfFiles, False, "/Test_Folder/" & pdfFiles)
Wait For (sf) FTP_UploadCompleted (ServerPath As String, Success As Boolean)
Log(ServerPath & ": "& Success)
End If
Next
FTP.Close