Hi guys!
I'm losing a customer because of the damned network library!
For my app is created a csv file and then upload to a FTP in passive mode under 3G network
I'm facing the following situations:
- the file is uploaded, the sub ftp_uploaded completed raise no error (strange that if I put a msgbox in the success event, it never shows!!) but it never arrives on the remote FTP
- the file arrives and is 0 Kb!
my customer is very angry and I don't know how to fix this, the app runs on Android 4.0
  
please help!
this is my code for creating and sending over FTP the file
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			I'm losing a customer because of the damned network library!
For my app is created a csv file and then upload to a FTP in passive mode under 3G network
I'm facing the following situations:
- the file is uploaded, the sub ftp_uploaded completed raise no error (strange that if I put a msgbox in the success event, it never shows!!) but it never arrives on the remote FTP
- the file arrives and is 0 Kb!
my customer is very angry and I don't know how to fix this, the app runs on Android 4.0
please help!
this is my code for creating and sending over FTP the file
			
				B4X:
			
		
		
		Sub Panel1_Click 'invio dati
   Dim server As ServerSocket 
   server.Initialize(0, "")
   If server.GetMyIP = "127.0.0.1" Then  'this is the localhost address
    'no connection
      Msgbox2("Nessuna Connessione!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_256.png"))
   Else
      Dim Answ As Int
      Answ=Msgbox2("Confermi Invio Dati?",Main.nomeprog,"Si","","No",LoadBitmap (File.DirAssets, "warning_256.png"))
      If Answ=DialogResponse.POSITIVE Then
         TxtLog.Text=" "
         Awake.KeepAlive(True) 'evitiamo lo stand by
         ProgressBar1.Visible = True
         TxtLog.Visible = True
         LblStatus.Visible = True
         LblProgress.Visible = True
         ProgressBar1.Progress = 0
         CheckBox1.Enabled = False
         Panel1.Enabled = False
         Panel2.Enabled = False
         Panel3.Enabled = False
         fileord = ""
         fileinc = ""
         ' generiamo prima il nome del file ordini
         Dim dataexp As String
         Dim now As Long
         now = DateTime.now
         fileord = "ordini"&DateTime.GetYear(now)
         If DateTime.GetMonth(now) < 10 Then
            fileord = fileord&"0"&DateTime.GetMonth(now)
         Else
            fileord = fileord&""&DateTime.GetMonth(now)
         End If
         If DateTime.GetDayOfMonth(now) < 10 Then
            fileord = fileord&"0"&DateTime.GetDayOfMonth(now)
         Else
            fileord = fileord&""&DateTime.GetDayOfMonth(now)
         End If
         If DateTime.GetHour(now) < 10 Then
            fileord = fileord&"0"&DateTime.GetHour(now)
         Else
            fileord = fileord&""&DateTime.GetHour(now)
         End If
         If DateTime.GetMinute(now) < 10 Then
            fileord = fileord&"0"&DateTime.GetMinute(now)
         Else
            fileord = fileord&""&DateTime.GetMinute(now)
         End If
         If DateTime.GetSecond(now) < 10 Then
            fileord = fileord&"0"&DateTime.GetSecond(now)
         Else
            fileord = fileord&""&DateTime.GetSecond(now)
         End If
         fileord = fileord&"_"&IdAge.Trim&".csv"
         dataexp = fileord.SubString2(12,14)&"/"&fileord.SubString2(10,12)&"/"&fileord.SubString2(6,10)
         ' recuperiamo i dati da inserire nel file csv da inviare
         Dim numfiles As Int
         numfiles = 0
         ' ordini
         Dim stringarecord,note_ord As String
         Dim Cursor1 As Cursor
         Dim List1 As List
             List1.Initialize
         Cursor1 = SQL1.ExecQuery("SELECT Seriale,IdOrd,IdCli,IdArt,Um,QtaOrd,QtaOma,ImpUni,Sconto1,Sconto2,Sconto3,Sconto4,AliIva,DataCons,NoteOrd from ORDINI where DataExp = 'NO'")
         If Cursor1.RowCount > 0 Then
            TxtLog.Text = "Creato File "& fileord &Chr(10)&TxtLog.Text
            For i = 0 To Cursor1.RowCount - 1
                 Cursor1.Position = i
               note_ord=Cursor1.GetString("NoteOrd")
               note_ord = note_ord.Replace(Chr(10),"; ") 'normalizzo il multiriga delle note su unica riga
                  stringarecord=Cursor1.GetString("Seriale")&Chr(9)
               stringarecord=stringarecord &Cursor1.GetString("IdOrd")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("IdCli")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("IdArt")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("Um")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("QtaOrd")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("QtaOma")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("ImpUni")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("Sconto1")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("Sconto2")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("Sconto3")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("Sconto4")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("AliIva")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("DataCons")&Chr(9)
               stringarecord=stringarecord &" " ¬e_ord
               List1.Add(stringarecord)
                ' inseriamo adesso la DataExp sulle righe dell'ordine
               Dim WhereFields As Map
               WhereFields.Initialize
               WhereFields.Put("Seriale", Cursor1.GetString("Seriale"))
               DBUtils.UpdateRecord(SQL1, "Ordini", "DataExp", dataexp, WhereFields)
            Next
            Cursor1.Close
            File.WriteList(sdRoot,fileord,List1)
            numfiles = numfiles + 1
            ProgressBar1.Progress = 25
            If FTPMode="F" Then    'connessione FTP
               TxtLog.Text = "Connessione FTP "& FTPHost &"(" &FTPPort &")" &" in Corso..." &Chr(10)&TxtLog.Text
               TxtLog.Text = "Invio File "& fileord &Chr(10)&TxtLog.Text
               FTP.UploadFile(sdRoot, fileord, True, fileord)
            End If
            If FTPMode="L" Then    'file locali
               ProgressBar1.Progress = ProgressBar1.Progress + 25
            End If
         Else
            numfiles = numfiles
         End If
      
         ' incassi
         fileinc = "incassi"&fileord.SubString(7)
         List1.Initialize
         Cursor1 = SQL1.ExecQuery("SELECT Seriale,IdPar,IdCli,ImpInc,DataInc from PARAPE where DataExp = 'NO' and ImpInc <>'0'")
         If Cursor1.RowCount > 0 Then
            TxtLog.Text = "Creato File "& fileinc &Chr(10)&TxtLog.Text
            For i = 0 To Cursor1.RowCount - 1
                 Cursor1.Position = i
               stringarecord=Cursor1.GetString("Seriale")&Chr(9)
                  stringarecord=stringarecord &Cursor1.GetString("IdPar")&Chr(9)
               stringarecord=stringarecord &Cursor1.GetString("IdCli")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("ImpInc")&Chr(9)
               stringarecord=stringarecord &" " &Cursor1.GetString("DataInc")&Chr(9)
               List1.Add(stringarecord)
                ' inseriamo adesso la DataExp sulle righe degli incassi
               Dim WhereFields As Map
               WhereFields.Initialize
               WhereFields.Put("Seriale", Cursor1.GetString("Seriale"))
               DBUtils.UpdateRecord(SQL1, "Parape", "DataExp", dataexp, WhereFields)
            Next
            Cursor1.Close
            File.WriteList(sdRoot,fileinc,List1)
            numfiles = numfiles + 1
            ProgressBar1.Progress = 75
            If FTPMode="F" Then    'connessione FTP
               TxtLog.Text = "Invio File "& fileinc &Chr(10)&TxtLog.Text
               FTP.UploadFile(sdRoot, fileinc, True, fileinc)
            End If
            If FTPMode="L" Then    'file locali
               ProgressBar1.Progress = ProgressBar1.Progress + 25
            End If
         Else   
            numfiles=numfiles
         End If
      
         If numfiles = 0 Then    'nè ordini nè incassi
            Msgbox2("Non ci Sono Dati da Inviare!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_256.png"))
            LblStatus.Visible = False
            LblProgress.Visible = False
            ProgressBar1.Visible = False
            TxtLog.Visible = False
            Awake.ReleaseKeepAlive 'togliamo lo standby
            CheckBox1.Enabled = True
            Panel1.Enabled = True
            Panel2.Enabled = True
            Panel3.Enabled = True
            Activity.Finish
            StartActivity(Main)
         Else
            ProgressBar1.Progress = 100
            Timer1.Initialize("Timer1",4000)
            Timer1.Enabled=True
         End If   
      End If
   End If
End Sub
Sub Timer1_Tick
   Msgbox2("Invio completato!"&CRLF&"E' Necessario Uscire e Rientrare nel programma",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_256.png"))
   If FTPMode="F" Then    
      'chiudo la connessione FTP
      FTP.Close
   End If
   File.Delete(sdRoot,fileord.Trim)
   File.Delete(sdRoot,fileinc.Trim)
   LblStatus.Visible = False
   LblProgress.Visible = False
   ProgressBar1.Visible = False
   TxtLog.Visible = False
   Awake.ReleaseKeepAlive 'togliamo lo standby
   CheckBox1.Enabled = True
   Panel1.Enabled = True
   Panel2.Enabled = True
   Panel3.Enabled = True
   Activity.Finish
'   StartActivity(Main)
   ExitApplication
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)
   LblProgress.Text = s
End Sub
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
   If Success = True Then
      ProgressBar1.Progress = ProgressBar1.Progress + 25
'      If ProgressBar1.Progress = 50 Then
         ' inseriamo adesso la DataExp sulle righe degli ordini
'         Dim dataexp As String
'         dataexp = fileord.SubString2(12,14)&"/"&fileord.SubString2(10,12)&"/"&fileord.SubString2(6,10)
'         Dim Reader As TextReader
'         Reader.Initialize(File.OpenInput(sdRoot, fileord))
 '           Dim line As String
  '          Dim WhereFields As Map
'         Do While line <> Null 
'                Try
'               line = Reader.ReadLine.SubString2(0,14)
'               WhereFields.Initialize
'               WhereFields.Put("IdOrd", line)
'               DBUtils.UpdateRecord(SQL1, "Ordini", "DataExp", dataexp, WhereFields)
'            Catch
 '                   Log(LastException.Message)
  '              End Try
'         Loop
'      End If
'      If ProgressBar1.Progress = 100 Then
         ' inseriamo adesso la DataExp sulle righe degli incassi
'         Dim Reader As TextReader
'         Reader.Initialize(File.OpenInput(sdRoot, fileinc))
 '           Dim line As String
  '          Dim WhereFields As Map
'         Do While line <> Null 
'                Try
'               line = Reader.ReadLine.SubString2(0,4)
'               line = line.Trim
'               WhereFields.Initialize
'               WhereFields.Put("Seriale", line)
'               DBUtils.UpdateRecord(SQL1, "Parape", "DataExp", dataexp, WhereFields)
'            Catch
 '                   Log(LastException.Message)
'            End Try
'         Loop
'      End If
   Else
      Log(LastException.Message)
      Msgbox2("Errore nell'Invio!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_256.png"))
   End If
End Sub
			
				Last edited: 
			
		
	
								
								
									
	
								
							
							 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		