German FTP - Hilfe nötig

pjo12345

Active Member
Licensed User
Longtime User
Hallo,

ich möchte eine Datei auf einen ftp-Server hoch- und runterladen. Der Code ist im Prinzip der aus dem Tutorial.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim FTP As FTP
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
        FTP.Initialize("FTP", "abcdef.de", 21, "user", "password")
    End If
   FTP.PassiveMode = False
   Activity.LoadLayout("mainftp")
   File.Copy(File.DirAssets,"test.jpg",File.DirDefaultExternal,"test.jpg")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed = True Then
      FTP.CloseNow
      Activity.Finish
   End If
End Sub

Sub Button2_Click
   FTP.DownloadFile("/upload/test.jpg", False, File.DirDefaultExternal, "test2.jpg")
End Sub
Sub Button1_Click
   FTP.UploadFile(File.DirDefaultExternal, "test.jpg", False, "/upload/test.jpg")
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)
End Sub

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)
End Sub

Es will aber nicht so richtig funktionieren. Beim Hochladen wird die Datei korrekt auf dem ftp-Server abgelegt aber Success ist immer false.
Das Runterladen funktioniert nicht. Der Download startet aber mittendrin bleibt er stehen. Er wird nie beendet. Die Datei ist 277kB groß. Was mache ich falsch?

Hier der Log:

Upload:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Uploaded 1KB
Uploaded 2KB
Uploaded 3KB
Uploaded 4KB
.....
Uploaded 273KB
Uploaded 274KB
Uploaded 275KB
Uploaded 276KB
Uploaded 278KB
Uploaded 278KB
/upload/test.jpg, Success=false
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.

Download:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Downloaded 1KB
Downloaded 1KB
Downloaded 2KB
Downloaded 3KB
Downloaded 4KB
....
Downloaded 197KB
Downloaded 197KB
Downloaded 198KB
Downloaded 199KB
Downloaded 200KB

Auch funktioniert meine App nicht, wenn der Download gleich nach dem Upload gestartet wird. (Broken Pipe)

Hat irgendwer ein paar Tipps für mich? Danke schon mal.
 

pjo12345

Active Member
Licensed User
Longtime User
Mit einem anderen ftp-Server (Free-Webhoster) funktionierts. Bei meinem NAS (via dyndns.org) läuft es wie im Post vorher beschrieben.
 

kaplanerkan

Member
Licensed User
Longtime User
Du benutzst active mode. Dh. die ports 20 und 21 muss auf dem router zu deinem nas server weitergeleitet werden, denn die anfragen gehen auf dem port 21 aber die dateiuberftragung geht uber das port 20.

Nur meine teori.
Gruss
erkan
 

pjo12345

Active Member
Licensed User
Longtime User
Funktioniert leider auch nicht. Scheint an meinem NAS zu liegen.
 
Top