nopnop2002 / esp-idf-ftpClient

ftp client for esp-idf
37 stars 7 forks source link

FTP transfer fails often when using cellular internet connection #8

Closed idea--list closed 8 months ago

idea--list commented 1 year ago

Have been using this repo for a while and am pretty much satisfied with it. Recently i noticed FTP transfer often fails while i have no WiFi router near me and i connect the ESP32S3 to the mobile hotspot of my Samsung Galaxy S7 while being on cellular internet connection. However while i am home and i also turn on wifi-sharing via the mobile hotspot on my phone then ftp transfers are OK.

First i thought it is some phone/android specific issue, but today i also tried a Huawei E5573 router, which does not run android and even this device fails to transfer about 50% of cases.

It seems that the ESP32S3 does always connect&login to the FTP server while using cellular connection of both the mobile phone and the Huawei router, but then it often hangs somewhere inside xfer() function which also does not return any integer values and thus the whole program hangs.

I aso tried to search for the cause of it, i found some entries telling it might a DHCP issue on some Samsung phones, but in that case i would not expect the same issue on my Huawei router... So ultimately i have no clue what might be causing it.

Here is a screenshot with DEBUG level 2 enabled when it hangs, hope it tells anything useful for someone who is more involved: error

nopnop2002 commented 1 year ago

Does the same phenomenon occur not only with ftp but also with protocols such as mqtt and ntp?

idea--list commented 1 year ago

Thanks for the quick reply @nopnop2002 ! The project into which i integrated this repo also communicates over MQTT and all messages arrive to the defined MQTT broker while being connected via cellular internet. Only FTP transfers seem to be affected by some reason. I took the screenshot while running this original repo to exclude any effects of user added code.

nopnop2002 commented 1 year ago

Unlike MQTT, FTP uses two TCP ports.

This example uses passive mode by default.

https://github.com/nopnop2002/esp-idf-ftpClient/blob/master/main/FtpClient.c#L38

What happens if you change to active mode?

idea--list commented 1 year ago

I face the same symptoms even when using active mode, i do not even see a better success rate.

nopnop2002 commented 1 year ago

I don't know what the problem is.

idea--list commented 1 year ago

I plan to setup an FTP server on my PC and access that over the internet. I would like to find out my hosting service has some bad settings or maybe even my mobile provider has some limitation... however first i will have to contact my ISP as they changed the firmware on my router and i can not setup any port forwarding to reach my own FTP server from outside. Will update this ticket as soon as i have any new information.

idea--list commented 1 year ago

Turns out my cellular provider allocates NATed IP addresses, while my normal router at home has public IP. As we are out of IPv4 range more and more ISP providers share 1 IP using NAT, especially in case of cellular internet access as the majority of people do not notice its negative effects while just browsing webpages. I think this might be the cause.

Have set up an FTP server on my desktop and i can reach it using an android ftp client via my local WiFi using both IPv4 and IPv6 addresses, though i still can not reach it from outside. The FTP server of my hosting provider has an IPv4 address and i am not sure if i should ask them for an IPv6 to reach the server as i do not know if this repo supports IPv6 addresses.