Skip to content

net: lib: ftp_client: Add FTP client library #104316

Merged
aescolar merged 3 commits intozephyrproject-rtos:mainfrom
rlubos:net/ftp-client
Feb 24, 2026
Merged

net: lib: ftp_client: Add FTP client library #104316
aescolar merged 3 commits intozephyrproject-rtos:mainfrom
rlubos:net/ftp-client

Conversation

@rlubos
Copy link
Contributor

@rlubos rlubos commented Feb 20, 2026

Add FTP client library, based on Nordic's FTP client library from NCS, along with FTP shell module and a minimal sample.

@rlubos rlubos force-pushed the net/ftp-client branch 3 times, most recently from d1887bc to f75671d Compare February 20, 2026 15:43
Copy link
Contributor

@pdgendt pdgendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Comment on lines 56 to 62
FTP_CODE_110 = 110,
/** Service ready in nnn minutes */
FTP_CODE_120 = 120,
/** Data connection already open; transfer starting */
FTP_CODE_125 = 125,
/** File status okay; about to open data connection */
FTP_CODE_150 = 150,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I don't see the benefit of using FTP_CODE_XXX instead of using XXX directly. I'd prefer to have some actual code names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update the names, something like FTP_CODE_150_FILE_STATUS_OK etc. would work, or do you think we should drop the number from the name entirely?

Copy link
Contributor

@pdgendt pdgendt Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have descriptive names, both with or without number is fine for me.

@rlubos rlubos requested a review from SeppoTakalo February 23, 2026 08:43
@sylvioalves
Copy link
Contributor

@rlubos do you plan to fix those sonarqube warnings like Access of the field 'ctrl_buf' at an overflowing index, while it holds only 0 'unsigned char' elements? and Refactor this function to reduce its Cognitive Complexity from 27 to the 25 allowed.?

@rlubos
Copy link
Contributor Author

rlubos commented Feb 23, 2026

@rlubos do you plan to fix those sonarqube warnings like Access of the field 'ctrl_buf' at an overflowing index, while it holds only 0 'unsigned char' elements? and Refactor this function to reduce its Cognitive Complexity from 27 to the 25 allowed.?

Yes, I have them fixed locally already (at least I hope so), will push soon. However, I must admit I am pretty confused with the Access of the field 'ctrl_buf' at an overflowing index, while it holds only 0 'unsigned char error, either I miss something or it's a false positive, however, I've moved the out-of-bound check into the loop to see if it silences the sonarqube.

@sylvioalves
Copy link
Contributor

@rlubos do you plan to fix those sonarqube warnings like Access of the field 'ctrl_buf' at an overflowing index, while it holds only 0 'unsigned char' elements? and Refactor this function to reduce its Cognitive Complexity from 27 to the 25 allowed.?

Yes, I have them fixed locally already (at least I hope so), will push soon. However, I must admit I am pretty confused with the Access of the field 'ctrl_buf' at an overflowing index, while it holds only 0 'unsigned char error, either I miss something or it's a false positive, however, I've moved the out-of-bound check into the loop to see if it silences the sonarqube.

The issue lies here:

#if defined(CONFIG_FTP_CLIENT)
#define FTP_BUFFER_SIZE CONFIG_FTP_CLIENT_BUF_SIZE
#else
#define FTP_BUFFER_SIZE 0
#endif

So ctrl_buf[0] is set when CONFIG_FTP_CLIENT is not defined (weird anyway).

@rlubos
Copy link
Contributor Author

rlubos commented Feb 23, 2026

@rlubos do you plan to fix those sonarqube warnings like Access of the field 'ctrl_buf' at an overflowing index, while it holds only 0 'unsigned char' elements? and Refactor this function to reduce its Cognitive Complexity from 27 to the 25 allowed.?

Yes, I have them fixed locally already (at least I hope so), will push soon. However, I must admit I am pretty confused with the Access of the field 'ctrl_buf' at an overflowing index, while it holds only 0 'unsigned char error, either I miss something or it's a false positive, however, I've moved the out-of-bound check into the loop to see if it silences the sonarqube.

The issue lies here:

#if defined(CONFIG_FTP_CLIENT)
#define FTP_BUFFER_SIZE CONFIG_FTP_CLIENT_BUF_SIZE
#else
#define FTP_BUFFER_SIZE 0
#endif

So ctrl_buf[0] is set when CONFIG_FTP_CLIENT is not defined (weird anyway).

Ah, thanks for the tip! Maybe just changing 0 to 1 will be enough then. I'll try that

Add FTP client library, based on the FTP client library from nRF Connect
SDK.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add FTP shell module covering basic FTP client operations.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add a minimal FTP client sample, exposing FTP operations via network
shell.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
@rlubos
Copy link
Contributor Author

rlubos commented Feb 23, 2026

In latest push:

  • All review feedback should've been addressed,
  • sonarqube issues should be fixed (we'll see that later),
  • some extra changes regarding input validation and PASV message parsing based on internal feedback
break;
}

if (client->ctrl_len >= sizeof(client->ctrl_buf) - 1) {
Copy link
Contributor

@sylvioalves sylvioalves Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also handle this line in the case where CONFIG_FTP_CLIENT is not set? Also, if CONFIG_FTP_CLIENT is not set, why is this being tested/included? Sounds unreal scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this whole file won't even be compiled if CONFIG_FTP_CLIENT is unset. Other thing is the header file, which may be included unconditionally (like in the shell module introduced in other commit), so we need those safeguards for undefined symbols.

I guess sonarqube just don't understand CMake/Kconfig dependencies, hence it assumes the file could be compiled anyway...

Copy link
Contributor

@sylvioalves sylvioalves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rlubos I forgot to ask. Should it have some kind of test case or only the sample would be enough?

@rlubos
Copy link
Contributor Author

rlubos commented Feb 24, 2026

@rlubos I forgot to ask. Should it have some kind of test case or only the sample would be enough?

For the initial release I've only considered the sample, as verifying FTP in ztest would be tricky w/o a FTP server to test against.

@aescolar aescolar merged commit 653ebcc into zephyrproject-rtos:main Feb 24, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment