Module for file transfer via FTP(S).
Upload a local file to an FTP server:
character(len=*), parameter :: HOST = '192.168.0.100'
character(len=*), parameter :: LOCAL_FILE = '/tmp/observ.csv'
character(len=*), parameter :: REMOTE_FILE = 'test/observ.csv'
integer :: rc
type(ftp_server_type) :: server
rc = dm_ftp_init()
call dm_ftp_server_set(server, host=HOST, create_missing=.true.)
rc = dm_ftp_upload(server, LOCAL_FILE, REMOTE_FILE)
call dm_ftp_shutdown()
If remote directory test/
does not exist, it will be created. The
remote path is relative to the default directory of the FTP server.
Absolute paths have to start with //
.
Download remote file test/observ.csv
instead:
call dm_ftp_server_set(server, host=HOST)
if (dm_file_exists(LOCAL_FILE)) call dm_file_delete(LOCAL_FILE)
rc = dm_ftp_download(server, REMOTE_FILE, LOCAL_FILE)
An existing local file has to be deleted first, or dm_ftp_download()
returns error E_EXIST
.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=*), | public, | parameter | :: | FTP_USER_AGENT | = | 'DMPACK '//DM_VERSION_STRING |
User agent of FTP client. |
integer, | public, | parameter | :: | FTP_HOST_LEN | = | 256 |
Max. host length. |
integer, | public, | parameter | :: | FTP_USERNAME_LEN | = | 32 |
Max. user name length. |
integer, | public, | parameter | :: | FTP_PASSWORD_LEN | = | 32 |
Max. password length. |
integer, | public, | parameter | :: | FTP_URL_LEN | = | 2048 |
Max. URL length. |
FTP server type.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
character(len=FTP_HOST_LEN), | public | :: | host | = | ' ' |
IP address or FQDN of FTP server. |
|
integer, | public | :: | port | = | 0 |
Control port (0 for default port 21). |
|
character(len=FTP_USERNAME_LEN), | public | :: | username | = | ' ' |
User name (empty for none). |
|
character(len=FTP_PASSWORD_LEN), | public | :: | password | = | ' ' |
Password (empty for none). |
|
integer, | public | :: | accept_timeout | = | 5 |
Accept timeout [sec]. |
|
integer, | public | :: | connect_timeout | = | 30 |
Connection timeout [sec]. |
|
integer, | public | :: | timeout | = | 30 |
Response timeout [sec]. |
|
logical, | public | :: | active | = | .false. |
Active mode. |
|
logical, | public | :: | create_missing | = | .false. |
Create missing directories. |
|
logical, | public | :: | tls | = | .false. |
Use Transport-Layer Security (FTPS). |
|
logical, | public | :: | verify_tls | = | .false. |
Verify SSL certificate. |
Downloads remote file from FTP server.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ftp_server_type), | intent(inout) | :: | server |
FTP server type. |
||
character(len=*), | intent(in) | :: | remote_file |
Path of remote file. |
||
character(len=*), | intent(in) | :: | local_file |
Path of file to upload. |
||
character(len=:), | intent(out), | optional, | allocatable | :: | error_message |
Error message. |
integer, | intent(out), | optional | :: | error_curl |
cURL error code. |
|
logical, | intent(in), | optional | :: | debug |
Output debug messages. |
Converts cURL easy stack error code to DMPACK error code.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | error_curl |
cURL easy error code. |
Return message associated with given cURL error code as allocatable character string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | error_curl |
cURL error code. |
Error message.
Initialises FTP backend. The function returns E_FTP
on error.
Uploads local file to FTP server.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ftp_server_type), | intent(inout) | :: | server |
FTP server type. |
||
character(len=*), | intent(in) | :: | local_file |
Path of file to upload. |
||
character(len=*), | intent(in) | :: | remote_file |
Path of remote file. |
||
character(len=*), | intent(in), | optional | :: | rename_file_to |
File name to rename to remote file to. |
|
character(len=:), | intent(out), | optional, | allocatable | :: | error_message |
Error message. |
integer, | intent(out), | optional | :: | error_curl |
cURL error code. |
|
logical, | intent(in), | optional | :: | debug |
Output debug messages. |
Returns allocatable string of FTP server URL in the form
ftp[s]://host[:port]/path
. An absolute path has to start with
//
. Uses the URL API of libcurl to create the URL. By default,
Transport-Layer Security (FTPS) is disabled.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | host |
FTP host. |
||
integer, | intent(in), | optional | :: | port |
FTP port (up to 5 digits). |
|
character(len=*), | intent(in), | optional | :: | path |
FTP file path. |
|
logical, | intent(in), | optional | :: | tls |
Enable Transport-Layer Security. |
URL of FTP server.
C-interoperable discard download function for libcurl. Do not call this function directly.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in), | value | :: | ptr |
C pointer to a chunk of memory. |
|
integer(kind=c_size_t), | intent(in), | value | :: | sz |
Always 1. |
|
integer(kind=c_size_t), | intent(in), | value | :: | nmemb |
Size of the memory chunk. |
|
type(c_ptr), | intent(in), | value | :: | data |
C pointer to argument passed by caller. |
Function return value.
C-interoperable upload callback function for libcurl. Do not call this function directly.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in), | value | :: | ptr |
C pointer to a chunk of memory. |
|
integer(kind=c_size_t), | intent(in), | value | :: | sz |
Always 1. |
|
integer(kind=c_size_t), | intent(in), | value | :: | nmemb |
Size of the memory chunk. |
|
type(c_ptr), | intent(in), | value | :: | data |
C pointer to argument passed by caller. |
Function return value.
C-interoperable download callback function for libcurl. Do not call this function directly.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in), | value | :: | ptr |
C pointer to a chunk of memory. |
|
integer(kind=c_size_t), | intent(in), | value | :: | sz |
Always 1. |
|
integer(kind=c_size_t), | intent(in), | value | :: | nmemb |
Size of the memory chunk. |
|
type(c_ptr), | intent(in), | value | :: | data |
C pointer to argument passed by caller. |
Function return value.
Cleans up FTP backend.
Prints FTP connection type to standard output or given file unit.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ftp_server_type), | intent(inout) | :: | server |
FTP server type. |
||
integer, | intent(in), | optional | :: | unit |
File unit. |
Sets attributes of given server type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ftp_server_type), | intent(inout) | :: | server |
FTP server type. |
||
character(len=*), | intent(in), | optional | :: | host |
Host. |
|
integer, | intent(in), | optional | :: | port |
Port (or 0 for default). |
|
character(len=*), | intent(in), | optional | :: | username |
User name. |
|
character(len=*), | intent(in), | optional | :: | password |
Password. |
|
integer, | intent(in), | optional | :: | accept_timeout |
Accept timeout [sec]. |
|
integer, | intent(in), | optional | :: | connect_timeout |
Connection timeout [sec]. |
|
integer, | intent(in), | optional | :: | timeout |
Response timeout [sec]. |
|
logical, | intent(in), | optional | :: | active |
Enable active mode. |
|
logical, | intent(in), | optional | :: | create_missing |
Create missing directories. |
|
logical, | intent(in), | optional | :: | tls |
Enable Transport-Layer Security. |
|
logical, | intent(in), | optional | :: | verify_tls |
Verify SSL cert. |