Android Question save text file on ftp server

Ralf Schappo

Member
Licensed User
hello
I'm brand new to this and I try to upload and download a text file to my ftp server but all it is doing it creats a file on the server but no content 0 kb. I use the follow code to do this. thanks for your help

Ralf


ftp.Initialize("ftp","47.71.228.110","200","xxxxx","xxxxx"
ftp.UploadFile(File.DirRootExternal,"new.txt",True,"new.txt")
 

DonManfred

Expert
Licensed User
Longtime User
You need to post a more complete code. I dont see how you are handling the events.
Best is to upload a small example project which shows the problem....

From the IDE: File->Export as zip (you can replace the logincredentials before exporting as zip....)

pd: welcome to the community!
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    ftp.Initialize("FTP","basic4android.de",21,"xxxxx","xxxxxx")
    ftp.List("/")
    ftp.UploadFile(...)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Log($"FTP_UploadProgress(${ServerPath}, ${TotalUploaded}, ${Total})"$)   
End Sub
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    Log($"FTP_UploadCompleted(${ServerPath}, ${Success})"$)
End Sub
Sub FTP_DownloadCompleted (ServerPath As String, Success As Boolean)
    Log($"FTP_DownloadCompleted (${ServerPath}, ${Success})"$)
End Sub
Sub FTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)
    Log($"FTP_ListCompleted(${ServerPath},${Folders.Length},${Files.Length})"$)
    If Files.Length>0 Then
        For i = 0 To Files.Length-1
            Dim fle As FTPEntry = Files(i)
            ftp.DownloadFile("/"&fle.Name,False,File.DirRootExternal,fle.Name)
        Next
    End If
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Î got your private message but i´m not able to answer.Seems some privacy setting in your account do not allow to answer.

Irgendwas in deinen Privaca-Einstellungen hier im Forum scheint nicht zu passen.
https://www.b4x.com/android/forum/account/privacy
Möglicherweise die Einstellung "Start conversations with you:"
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User
you should never use ftp to just upload txt file to your ftp server
anyone can decompile you apk and see ftp username and password
the right way is to use php file and post the text data to it then the ftp file write the text file
 
Upvote 0

Ralf Schappo

Member
Licensed User
ok sorry, I didn't know how to do that code tag.
here is the code to upload a file to my ftp server (usb on my router)

B4X:
Sub getFTP_Click
    Dim ftp As FTP
    ftp.PassiveMode=False
    ftp.Initialize("ftp","192.168.2.1","400","user","pass")     'works fine
    ftp.Initialize("ftp","my ip","400","user","pass")           'creates a 0 kb file name alt
    ftp.UploadFile(File.DirRootExternal,"new2.txt",False,"alt.txt")
    ftp.Close
End Sub

why the file has 0 kb when uploading through the wan and local it work fine
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…