B4A Library New Net library - Android FTP, SMTP and POP3

Discussion in 'Additional libraries, classes and official updates' started by Erel, Aug 17, 2011.

Thread Status:
Not open for further replies.
  1. xky

    xky Member Licensed User

    I use it and it work fine.
    But if I upload a file, if the file name is a UTF8 charactor, it will have 553 error.
    For example: 1.txt is uploaded OK; 你好.txt will be have 553 (could not create file) back.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    I was able to upload a file with that name to an FTP server. Though it seems like its name was later lost. The control channel uses ISO-8859-1 encoding.

    You can change it with this code:
    Code:
    Dim r As Reflector
    r.SetStaticField(
    "org.apache.commons.net.ftp.FTP""DEFAULT_CONTROL_ENCODING""UTF-8""java.lang.String")
    It didn't make any difference with the server I've tested.

    Interesting reading about this issue: https://wiki.filezilla-project.org/Character_Encoding
     
  3. xky

    xky Member Licensed User

    upload_2016-10-7_11-9-10.png
    I use a Linksys EA6700 Router, it has FTP, I tested each encode, but it still have the 553 problem. I added the Reflector as you given the code to me, it's not work.
    But I can drag a file name like 你好.txt to the FTP server with windows file manager. So I think there's something I can do but I don't know.
    Code:
    Sub Button3_Click
        CardList=
    File.ListFiles(File.DirDefaultExternal)
        
    If CardList.Size=0 Then Return
        
    Dim r As Reflector
        r.SetStaticField(
    "org.apache.commons.net.ftp.FTP""DEFAULT_CONTROL_ENCODING""UTF-8""java.lang.String")
        
    FTP.Initialize("FTP""server.lingker.com"21"ShowMe""00000000")
        
    Dim i As Byte
        
    Dim s As String
        
    For i = 0 To CardList.Size-1
            s=CardList.Get(i)
            
    FTP.UploadFile(File.DirDefaultExternal, s, True"/ShowMe/" & s)
        
    Next
        
    FTP.Close
    End Sub
    This is my code, you can use the infomation in code to connect my FTP for Test.
    I use CuteFTP to upload 测试这个文件.txt is OK. So I think B4A can do it too.
    FTP express pro is an android app, it can upload to my server with 测试这个文件.txt too. Why this lib can't?
     
    Last edited: Oct 9, 2016
  4. xky

    xky Member Licensed User

    It seems it do nothing, still not UTF-8.
     
  5. xky

    xky Member Licensed User

    This not work because "DEFAULT_CONTROL_ENCODING" only change default. but I need FTP.SetControlEncoding.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    It has the same effect.

    You can try to set the _controlEncoding directly with:
    Code:
    FTP.Initialize(...)
    Dim r As Refelector
    r.Target = 
    FTP
    r.Target = r.GetField(
    "client")
    r.SetField(
    "_controlEncoding""UTF8""java.lang.String")
    This is exactly like calling setControlEncoding.
     
  7. xky

    xky Member Licensed User

    Yeah,I'm very happy to tell you. It's worked. I can upload any name of file now.(such as 测试这个文件.txt)
    So I think it is different.
    Code:
    r.SetField("_controlEncoding""UTF8""java.lang.String")
    change current encoding to UTF-8 but
    Code:
    r.SetStaticField("org.apache.commons.net.ftp.FTP""DEFAULT_CONTROL_ENCODING""UTF-8""java.lang.String")
    not.
    I suggest add FTP.SetControlEncoding to the lib, for non-ASCII users.

    Thankyou very much for the helping.
     
  8. Bina

    Bina New Member Licensed User

    Hi Erel,
    when connectiong to an ftp is it using passive or active mode?
     
  9. DonManfred

    DonManfred Expert Licensed User

    [​IMG]
     
    Bina and Erel like this.
  10. MMORETTI964

    MMORETTI964 Member Licensed User

    I've a problem downloading (or uploading) a large file with FTP libraries.
    Should be something related to a firewall who closes the command connection.

    There are something I can use for keeping alive the connection (a keepalive socket option or a "NOOP" command - not-recommended but sometime useful - while transferring a file)?

    Thank you.

    Maurizio
     
  11. MarcoRome

    MarcoRome Expert Licensed User

    Do you see THIS
     
  12. MMORETTI964

    MMORETTI964 Member Licensed User

    I can't send a command on the same connection while a command is executing...
    I'm trying to change the KeepAlive on that server.
    I think if I could set KeepAlive on the command control (or send a NOOP on that command) I could bypass every firewall problem I would encounter on my way...

    Maurizio
     
  13. MarcoRome

    MarcoRome Expert Licensed User

    Do you see THIS solution
     
  14. MarcoRome

    MarcoRome Expert Licensed User

    Hi @Erel.
    Can i set a time-out in the current library type:
    ftpClient.setControlKeepAliveTimeout(xxx)
    or to use this command to 'keep-alive' ??
    Thank you
    Marco
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    You can access the underlying FTPClient with:
    Code:
    Dim r As Reflector
    r.Target = FTP1
    Dim client As JavaObject = r.GetField("client")
    Dim timoutSeconds As Long = 10
    client.RunMethod(
    "setControlKeepAliveTimeout"Array(timeoutSeconds))
     
    MarcoRome likes this.
  16. JackKirk

    JackKirk Well-Known Member Licensed User

  17. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread in the questions forum.
     
  18. aviario

    aviario Active Member Licensed User

    Hi. first of all, sorry for my english.
    We have a program in B4A 6.5 versión using this library to connect to Fillezilla FTP Server.
    Now we change to B4A 7.3 versión and the software not run. When we try to connect, the program not do it.
    There an update of library?

    tha
     
  19. DonManfred

    DonManfred Expert Licensed User

    The Lib can be found in #1 of this thread. V1.75 is the most up to date....

    If you have any issues. Create a new thread in the questionsforum.
    Post a small example project which shows the issue. Post the error too.
     
  20. Steini1980

    Steini1980 Member Licensed User

    Hi@all,
    after upgrading the NET-Library to newest Version 1.77 i got the following exception if I try to start my App:

    Code:
    Installing file.
    PackageAdded: package:b4a.dms.blabla
    java.lang.ClassNotFoundException: anywheresoftware$b4a$net$FTPWrapper
        at anywheresoftware.b4a.shell.Shell.getCorrectClassName(
    Shell.java:544)
        at anywheresoftware.b4a.shell.Shell.createObject(
    Shell.java:516)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:320)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:238)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    121)
        at b4a.dms.blabla.main.afterFirstLayout(main.java:
    91)
        at b4a.dms.blabla.main.access$
    100(main.java:16)
        at b4a.dms.blabla.main$WaitForLayout.run(main.java:
    76)
        at android.os.Handler.handleCallback(Handler.java:
    739)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    145)
        at android.app.ActivityThread.main(ActivityThread.java:
    6873)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    1404)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1199)
    Could you please help me?! does I have to delete anything before?
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice