Android Question Port number 20 or 21 for successful Upload to FTP server

Valeriy Lakhtin

Member
Licensed User
Hi all! I successfully use NET lib FTP for upload files. But I did not make file upload. I checked the user rights - the user have full administrator access for ftp server. What I need to set the port number on line
B4X:
ibFTP.Initialize("eventFTP", "ftp.inform.kz", 20, "#####", "111111")
21 or 20 for a successful upload file? And tell me which mode
B4X:
ibFTP.PassiveMode = False or True
is best used for stable uploading files to FTP server
 

KMatle

Expert
Licensed User
Longtime User
ibFTP.Initialize("eventFTP", "ftp.inform.kz", 20, "#####", "111111")

Usually you have to define an extra FTP account/user (do not mismatch that with the admin!) and try again. Which provider do you use?

Passive/Active: Just try. It's more about firewalls.
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
My provider is solid and reliable HOSTER - he placed our company website www.informbyuro.kz There is also a FTP server. Through the program FilelZila I checked the right to access in the root FTP folder all OK full access(r/w). Download files to my phone goes well, I can not upload my files from the phone to the FTP server. Checked all examples port must be 21.
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
I tried to catch the error with the help "Try Catch" but the error does not occur.
Sub _UploadCompleted (ServerPath As String, Success As Boolean) procedure reported that the variable Success=False
 
Upvote 0

Lee Gillie CCP

Active Member
Licensed User
Longtime User
This answers your question in general I believe. CLICK HERE

Having written FTP servers from scratch I can tell you one confounding issue with firewalls which do NAT (Network Address Translation). They tend to "tweak" the FTP command channel IP/PORT octets sent in commands/responses. Negotiation of a DATA CHANNEL involves sending the IP address and port to use. Internally on the LAN for the server, the IP might be 10.1.1.# for example. But to the outside world this IP might be 204.133.#.# for example. A firewall translates the external IP to internal on the FTP command channel traffic. So in order for the server to tell the client which IP to make its PASSIVE client initiated connection. If you are additionally protecting with SSL (FTPS) then the firewall can not see inside the outbound server response on the command channel to FIX the IP by changing LAN IP to EXTERNAL IP. Your server will have to do that fix-up itself, which requires tricks. If you are doing FTP in the clear, this is not an issue. From the client's perspective you have to know the IP and PORT given by the server will work well for PASSIVE, and in the clear, it is generally not a problem. If you use non-standard ports, your firewalls may not do this NAT corrections for you.

HTH
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
I use WiFi to access the Internet. I understand from your explanation that the passive method is more reliable. I try use for access to Internet G3 SIM card may be it will give more a good result? When i turn-OFF WiFi I have Error Log

libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
 
Upvote 0

Lee Gillie CCP

Active Member
Licensed User
Longtime User
Off the cuff, it sounds to me a lot like no access to DNS.

So, when you turn off wifi, does that mean you are then wire connected to the network?

Other discussions involving EAI_NODATA and FTP can be found: CLICK HERE

I've built systems allowing EITHER FTP or HTTP transport protocols consumed by higher level proprietary services, and most often find the use of HTTP to have fewer such issues. But then I have access for code to both SERVER and CLIENT.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Sub _UploadCompleted (ServerPath As String, Success As Boolean) procedure reported that the variable Success=False

We need the reason: Get the message like this: Log(LastException.Message)

B4X:
Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
  
    If Success = True Then
        Log("FTP-Upload: OK")
    Else
       Log(LastException.Message)
    End If
    FTP.Close
  
  
    WriteLog ("OK")
End Sub
 
Upvote 0

Valeriy Lakhtin

Member
Licensed User
I show in detail its code.
Error message
android.system.ErrnoException: open failed: ENOENT (No such file or directory)
indicates a problem with the file. I do not understand the reasons for the error. If the file "/clicklike/rating.xml" is overwritten why the program can not find it, and should not be "/ClickLike/rating_OK.xml" file on the FTP. This name "/ClickLike/rating_OK.xml" will be after a successful upload on FTP


B4X:
        xomBuild.Initialize("Activ")
        xomBuild.BuildFromString(str,"",Null)
        File.WriteString(File.DirRootExternal, "/clicklike/rating.xml", str)      

        If CheckInternet=True Then
            ibFTP.close
            ibFTP.Initialize("eeeFTP", "ftp.informbyuro.kz", 21, "####", "####")
            ibFTP.PassiveMode = False
            If     ibFTP.IsInitialized=True Then
                If File.Exists(File.DirRootExternal,"/clicklike/rating.xml")=True Then
                    ibFTP.UploadFile(File.DirDefaultExternal, "/clicklike/rating.xml", False, "/ClickLike/rating_OK.xml")  
                    Log("Файл подготовлен к отправлен на FTP сервер")
                    Else
                    Log("Нет файла для отправки на FTP сервер")                  
                End If
                Else
                Log("Не произошло подключение к FTP сервер")  
            End If
            Else
            Log("Нет доступа к Интернет")                  
        End If

B4X:
Sub eeeFTP_UploadCompleted (ServerPath As String, Success As Boolean)
If Success=True Then
    Log(ServerPath & " Отправка файла завершена успешно")
    Else
    Log(LastException.Message)
    Log(ServerPath & " Файл не отправлен!!!!!!!!!")
End If
End Sub
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
If File.Exists(File.DirRootExternal,"/clicklike/rating.xml")=True Then
ibFTP.UploadFile(File.DirDefaultExternal, "/clicklike/rating.xml", False, "/ClickLike/rating_OK.xml")

File.WriteString(File.DirRootExternal
If File.Exists(File.DirRootExternal...

vs.

ibFTP.UploadFile(File.DirDefaultExternal

It's not the same directoy!

File.DirRootExternal

The storage card root folder.

File.DirDefaultExternalThe default folder for your application in the SD card.
The folder is: <storage card>/Android/data/<package>/files/
It will be created if required.
 
Upvote 0
Top