ftp_client.c File Reference

FTP client (File Transfer Protocol) More...

#include <stdlib.h>
#include <ctype.h>
#include "ftp/ftp_client.h"
#include "ftp/ftp_client_transport.h"
#include "ftp/ftp_client_misc.h"
#include "str.h"
#include "error.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   FTP_TRACE_LEVEL
 

Functions

error_t ftpClientInit (FtpClientContext *context)
 Initialize FTP client context. More...
 
error_t ftpClientRegisterTlsInitCallback (FtpClientContext *context, FtpClientTlsInitCallback callback)
 Register TLS initialization callback function. More...
 
error_t ftpClientSetTimeout (FtpClientContext *context, systime_t timeout)
 Set communication timeout. More...
 
error_t ftpClientBindToInterface (FtpClientContext *context, NetInterface *interface)
 Bind the FTP client to a particular network interface. More...
 
error_t ftpClientConnect (FtpClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort, uint_t mode)
 Establish a connection with the specified FTP server. More...
 
error_t ftpClientLogin (FtpClientContext *context, const char_t *username, const char_t *password)
 Login to the FTP server using the provided user name and password. More...
 
error_t ftpClientLoginEx (FtpClientContext *context, const char_t *username, const char_t *password, const char_t *account)
 Login to the FTP server using user name, password and account. More...
 
error_t ftpClientGetWorkingDir (FtpClientContext *context, char_t *path, size_t maxLen)
 Get current working directory. More...
 
error_t ftpClientChangeWorkingDir (FtpClientContext *context, const char_t *path)
 Change working directory. More...
 
error_t ftpClientChangeToParentDir (FtpClientContext *context)
 Change to parent directory. More...
 
error_t ftpClientOpenDir (FtpClientContext *context, const char_t *path)
 Open a directory. More...
 
error_t ftpClientReadDir (FtpClientContext *context, FtpDirEntry *dirEntry)
 Read an entry from the directory. More...
 
error_t ftpClientCloseDir (FtpClientContext *context)
 Close directory. More...
 
error_t ftpClientMakeDir (FtpClientContext *context, const char_t *path)
 Create a new directory. More...
 
error_t ftpClientRemoveDir (FtpClientContext *context, const char_t *path)
 Remove a directory on the FTP server. More...
 
error_t ftpClientOpenFile (FtpClientContext *context, const char_t *path, uint_t mode)
 Open a file for reading, writing, or appending. More...
 
error_t ftpClientWriteFile (FtpClientContext *context, const void *data, size_t length, size_t *written, uint_t flags)
 Write to a remote file. More...
 
error_t ftpClientReadFile (FtpClientContext *context, void *data, size_t size, size_t *length, uint_t flags)
 Read from a remote file. More...
 
error_t ftpClientCloseFile (FtpClientContext *context)
 Close file. More...
 
error_t ftpClientRenameFile (FtpClientContext *context, const char_t *oldName, const char_t *newName)
 Rename a remote file. More...
 
error_t ftpClientDeleteFile (FtpClientContext *context, const char_t *path)
 Delete a file. More...
 
uint_t ftpClientGetReplyCode (FtpClientContext *context)
 Retrieve server's reply code. More...
 
error_t ftpClientDisconnect (FtpClientContext *context)
 Gracefully disconnect from the FTP server. More...
 
error_t ftpClientClose (FtpClientContext *context)
 Close the connection with the FTP server. More...
 
void ftpClientDeinit (FtpClientContext *context)
 Release FTP client context. More...
 
error_t ftpConnect (FtpClientContext *context, NetInterface *interface, const IpAddr *serverIpAddr, uint16_t serverPort, uint_t flags)
 

Detailed Description

FTP client (File Transfer Protocol)

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Description

File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another host over a TCP-based network. Refer to the following RFCs for complete details:

  • RFC 959: File Transfer Protocol (FTP)
  • RFC 2428: FTP Extensions for IPv6 and NATs
Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file ftp_client.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   FTP_TRACE_LEVEL

Definition at line 38 of file ftp_client.c.

Function Documentation

◆ ftpClientBindToInterface()

error_t ftpClientBindToInterface ( FtpClientContext context,
NetInterface interface 
)

Bind the FTP client to a particular network interface.

Parameters
[in]contextPointer to the FTP client context
[in]interfaceNetwork interface to be used
Returns
Error code

Definition at line 146 of file ftp_client.c.

◆ ftpClientChangeToParentDir()

error_t ftpClientChangeToParentDir ( FtpClientContext context)

Change to parent directory.

Parameters
[in]contextPointer to the FTP client context
Returns
Error code

Definition at line 696 of file ftp_client.c.

◆ ftpClientChangeWorkingDir()

error_t ftpClientChangeWorkingDir ( FtpClientContext context,
const char_t path 
)

Change working directory.

Parameters
[in]contextPointer to the FTP client context
[in]pathThe new current working directory
Returns
Error code

Definition at line 622 of file ftp_client.c.

◆ ftpClientClose()

error_t ftpClientClose ( FtpClientContext context)

Close the connection with the FTP server.

Parameters
[in]contextPointer to the FTP client context
Returns
Error code

Definition at line 1719 of file ftp_client.c.

◆ ftpClientCloseDir()

error_t ftpClientCloseDir ( FtpClientContext context)

Close directory.

Parameters
[in]contextPointer to the FTP client context
Returns
Error code

Definition at line 991 of file ftp_client.c.

◆ ftpClientCloseFile()

error_t ftpClientCloseFile ( FtpClientContext context)

Close file.

Parameters
[in]contextPointer to the FTP client context
Returns
Error code

Definition at line 1406 of file ftp_client.c.

◆ ftpClientConnect()

error_t ftpClientConnect ( FtpClientContext context,
const IpAddr serverIpAddr,
uint16_t  serverPort,
uint_t  mode 
)

Establish a connection with the specified FTP server.

Parameters
[in]contextPointer to the FTP client context
[in]serverIpAddrIP address of the FTP server
[in]serverPortPort number
[in]modeFTP connection mode
Returns
Error code

Definition at line 170 of file ftp_client.c.

◆ ftpClientDeinit()

void ftpClientDeinit ( FtpClientContext context)

Release FTP client context.

Parameters
[in]contextPointer to the FTP client context

Definition at line 1742 of file ftp_client.c.

◆ ftpClientDeleteFile()

error_t ftpClientDeleteFile ( FtpClientContext context,
const char_t path 
)

Delete a file.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the file to be be deleted
Returns
Error code

Definition at line 1530 of file ftp_client.c.

◆ ftpClientDisconnect()

error_t ftpClientDisconnect ( FtpClientContext context)

Gracefully disconnect from the FTP server.

Parameters
[in]contextPointer to the FTP client context
Returns
Error code

Definition at line 1630 of file ftp_client.c.

◆ ftpClientGetReplyCode()

uint_t ftpClientGetReplyCode ( FtpClientContext context)

Retrieve server's reply code.

Parameters
[in]contextPointer to the FTP client context
Returns
FTP reply code

Definition at line 1603 of file ftp_client.c.

◆ ftpClientGetWorkingDir()

error_t ftpClientGetWorkingDir ( FtpClientContext context,
char_t path,
size_t  maxLen 
)

Get current working directory.

Parameters
[in]contextPointer to the FTP client context
[out]pathOutput buffer where to store the current directory
[in]maxLenMaximum number of characters the buffer can hold
Returns
Error code

Definition at line 542 of file ftp_client.c.

◆ ftpClientInit()

error_t ftpClientInit ( FtpClientContext context)

Initialize FTP client context.

Parameters
[in]contextPointer to the FTP client context
Returns
Error code

Definition at line 60 of file ftp_client.c.

◆ ftpClientLogin()

error_t ftpClientLogin ( FtpClientContext context,
const char_t username,
const char_t password 
)

Login to the FTP server using the provided user name and password.

Parameters
[in]contextPointer to the FTP client context
[in]usernameNULL-terminated string containing the user name
[in]passwordNULL-terminated string containing the user's password
Returns
Error code

Definition at line 375 of file ftp_client.c.

◆ ftpClientLoginEx()

error_t ftpClientLoginEx ( FtpClientContext context,
const char_t username,
const char_t password,
const char_t account 
)

Login to the FTP server using user name, password and account.

Parameters
[in]contextPointer to the FTP client context
[in]usernameNULL-terminated string containing the user name
[in]passwordNULL-terminated string containing the user's password
[in]accountNULL-terminated string containing the user's account
Returns
Error code

Definition at line 392 of file ftp_client.c.

◆ ftpClientMakeDir()

error_t ftpClientMakeDir ( FtpClientContext context,
const char_t path 
)

Create a new directory.

Parameters
[in]contextPointer to the FTP client context
[in]pathThe name of the new directory
Returns
Error code

Definition at line 1009 of file ftp_client.c.

◆ ftpClientOpenDir()

error_t ftpClientOpenDir ( FtpClientContext context,
const char_t path 
)

Open a directory.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the directory to be be opened
Returns
Directory handle

Definition at line 770 of file ftp_client.c.

◆ ftpClientOpenFile()

error_t ftpClientOpenFile ( FtpClientContext context,
const char_t path,
uint_t  mode 
)

Open a file for reading, writing, or appending.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the file to be be opened
[in]modeFile access mode
Returns
Error code

Definition at line 1158 of file ftp_client.c.

◆ ftpClientReadDir()

error_t ftpClientReadDir ( FtpClientContext context,
FtpDirEntry dirEntry 
)

Read an entry from the directory.

Parameters
[in]contextPointer to the FTP client context
[out]dirEntryPointer to a directory entry
Returns
Error code

Definition at line 896 of file ftp_client.c.

◆ ftpClientReadFile()

error_t ftpClientReadFile ( FtpClientContext context,
void *  data,
size_t  size,
size_t *  length,
uint_t  flags 
)

Read from a remote file.

Parameters
[in]contextPointer to the FTP client context
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be read
[out]lengthActual number of bytes that have been read
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1357 of file ftp_client.c.

◆ ftpClientRegisterTlsInitCallback()

error_t ftpClientRegisterTlsInitCallback ( FtpClientContext context,
FtpClientTlsInitCallback  callback 
)

Register TLS initialization callback function.

Parameters
[in]contextPointer to the FTP client context
[in]callbackTLS initialization callback function
Returns
Error code

Definition at line 101 of file ftp_client.c.

◆ ftpClientRemoveDir()

error_t ftpClientRemoveDir ( FtpClientContext context,
const char_t path 
)

Remove a directory on the FTP server.

Parameters
[in]contextPointer to the FTP client context
[in]pathPath to the directory to be removed
Returns
Error code

Definition at line 1083 of file ftp_client.c.

◆ ftpClientRenameFile()

error_t ftpClientRenameFile ( FtpClientContext context,
const char_t oldName,
const char_t newName 
)

Rename a remote file.

Parameters
[in]contextPointer to the FTP client context
[in]oldNameThe name of the remote file to rename
[in]newNameThe new name of the remote file
Returns
Error code

Definition at line 1425 of file ftp_client.c.

◆ ftpClientSetTimeout()

error_t ftpClientSetTimeout ( FtpClientContext context,
systime_t  timeout 
)

Set communication timeout.

Parameters
[in]contextPointer to the FTP client context
[in]timeoutTimeout value, in milliseconds
Returns
Error code

Definition at line 125 of file ftp_client.c.

◆ ftpClientWriteFile()

error_t ftpClientWriteFile ( FtpClientContext context,
const void *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Write to a remote file.

Parameters
[in]contextPointer to the FTP client context
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of data bytes to write
[in]writtenNumber of bytes that have been written
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 1304 of file ftp_client.c.

◆ ftpConnect()

error_t ftpConnect ( FtpClientContext context,
NetInterface interface,
const IpAddr serverIpAddr,
uint16_t  serverPort,
uint_t  flags 
)

Definition at line 1763 of file ftp_client.c.