项目作者: embulk

项目描述 :
FTP file output plugin for Embulk
高级语言: Java
项目地址: git://github.com/embulk/embulk-output-ftp.git
创建时间: 2016-07-20T06:21:29Z
项目社区:https://github.com/embulk/embulk-output-ftp

开源协议:

下载


FTP file output plugin for Embulk

Build Status

This plugin support FTP, FTPES(FTPS explicit), FTPS(FTPS implicit) and doesn’t support SFTP.

If you want to use SFTP, please use embulk-output-sftp.

Overview

  • Plugin type: file input
  • Resume supported: no
  • Cleanup supported: yes

Configuration

  • host: FTP server address (string, required)
  • port: FTP server port number (integer, default: 21. 990 if ssl is true and ssl_explicit is false)
  • user: user name to login (string, optional)
  • password: password to login (string, default: "")
  • path_prefix prefix of target files (string, required)
  • sequence_format Format for sequence part of output files (string, default: ".%03d.%02d")
  • file_ext e.g. “csv.gz, json.gz” (string, required)
  • passive_mode: use passive mode (boolean, default: true)
  • ascii_mode: use ASCII mode instead of binary mode (boolean, default: false)
  • ssl: use FTPS (SSL encryption). (boolean, default: false)
  • ssl_explicit use FTPS(explicit) instead of FTPS(implicit). (boolean, default:true)
  • ssl_verify: verify the certification provided by the server. By default, connection fails if the server certification is not signed by one the CAs in JVM’s default trusted CA list. (boolean, default: true)
  • ssl_verify_hostname: verify server’s hostname matches with provided certificate. (boolean, default: true)
  • ssl_trusted_ca_cert_file: if the server certification is not signed by a certificate authority, set path to the X.508 certification file (pem file) of a private CA (string, optional)
  • ssl_trusted_ca_cert_data: similar to ssl_trusted_ca_cert_file but embed the contents of the PEM file as a string value instead of path to a local file (string, optional)

FTP / FTPS default port number

FTP and FTPS server listens following port number(TCP) as default.

Please be sure to configure firewall rules.

FTP FTPS(explicit) = FTPES FTPS(implicit) = FTPS
Control channel port 21 21 990 (*1)
Data channel port (*2) 20 20 989
  1. If you’re using both of FTPS(implicit) and FTP, server also use 21/TCP for FTP.
  2. If you’re using passive mode, data channel port can be taken between 1024 and 65535.

Example

Simple FTP:

  1. out:
  2. type: ftp
  3. host: ftp.example.net
  4. port: 21
  5. user: anonymous
  6. path_prefix: /ftp/file/path/prefix
  7. file_ext: csv
  8. formatter:
  9. type: csv.gz
  10. header_line: false
  11. encoders:
  12. - {type: gzip}

FTPS encryption without server certificate verification:

  1. out:
  2. type: ftp
  3. host: ftp.example.net
  4. port: 21
  5. user: anonymous
  6. password: "mypassword"
  7. ssl: true
  8. ssl_verify: false
  9. path_prefix: /ftp/file/path/prefix
  10. file_ext: csv

FTPS encryption with server certificate verification:

  1. out:
  2. type: ftp
  3. host: ftp.example.net
  4. port: 21
  5. user: anonymous
  6. password: "mypassword"
  7. ssl: true
  8. ssl_verify: true
  9. ssl_verify_hostname: false # to disable server hostname verification (optional)
  10. # if the server use self-signed certificate, or set path to the pem file (optional)
  11. ssl_trusted_ca_cert_file: /path/to/ca_cert.pem
  12. # or embed contents of the pem file here (optional)
  13. ssl_trusted_ca_cert_data: |
  14. -----BEGIN CERTIFICATE-----
  15. MIIFV...
  16. ...
  17. ...
  18. -----END CERTIFICATE-----
  19. path_prefix: /ftp/file/path/prefix
  20. file_ext: csv

Build

  1. $ ./gradlew gem # -t to watch change of files and rebuild continuously

Test

Firstly install Docker and Docker compose then docker-compose up -d,
so that an FTP server will be locally launched then you can run tests with ./gradlew test.

  1. $ docker-compose up -d
  2. Creating network "embulk-output-ftp_default" with the default driver
  3. Creating embulk-output-ftp_server ... done
  4. Creating embulk-output-ftps_server ... done
  5. $ docker-compose ps
  6. Name Command State Ports
  7. ---------------------------------------------------------------------------------------------------
  8. embulk-output-ftp_server /usr/sbin/run-vsftpd.sh Up 20/tcp, 0.0.0.0:11021->21/tcp, 0.0.0.0:65000->65000/tcp, 0.0.0.0:65001->65001/tcp, 0.0.0.0:65002->65002/tcp, 0.0.0.0:65003->65003/tcp,
  9. 0.0.0.0:65004->65004/tcp
  10. embulk-output-ftps_server /usr/sbin/run-vsftpd-with- ... Up 20/tcp, 0.0.0.0:990->21/tcp, 0.0.0.0:65005->65005/tcp, 0.0.0.0:65006->65006/tcp, 0.0.0.0:65007->65007/tcp, 0.0.0.0:65008->65008/tcp
  11. $ ./gradlew test # -t to watch change of files and rebuild continuously

If you want to use other FTP server to test, configure the following environment variables.

  1. FTP_TEST_HOST (default: localhost)
  2. FTP_TEST_PORT (default: 11021)
  3. FTP_TEST_SSL_PORT (default:990)
  4. FTP_TEST_USER (default: scott)
  5. FTP_TEST_PASSWORD (default: tigger)
  6. FTP_TEST_SSL_TRUSTED_CA_CERT_FILE
  7. FTP_TEST_SSL_TRUSTED_CA_CERT_DATA

If you’re using Mac OS X El Capitan and GUI Applications(IDE), like as follows.

  1. $ vi ~/Library/LaunchAgents/environment.plist
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  4. <plist version="1.0">
  5. <dict>
  6. <key>Label</key>
  7. <string>my.startup</string>
  8. <key>ProgramArguments</key>
  9. <array>
  10. <string>sh</string>
  11. <string>-c</string>
  12. <string>
  13. launchctl setenv FTP_TEST_HOST ftp.example.com
  14. launchctl setenv FTP_TEST_USER username
  15. launchctl setenv FTP_TEST_PASSWORD password
  16. launchctl setenv FTP_TEST_SSL_TRUSTED_CA_CERT_FILE /path/to/cert.pem
  17. launchctl setenv FTP_TEST_SSL_TRUSTED_CA_CERT_DATA "-----BEGIN CERTIFICATE-----
  18. ABCDEFG...
  19. EFGHIJKL...
  20. -----END CERTIFICATE-----"
  21. </string>
  22. </array>
  23. <key>RunAtLoad</key>
  24. <true></true>
  25. </dict>
  26. </plist>
  27. $ launchctl load ~/Library/LaunchAgents/environment.plist
  28. $ launchctl getenv FTP_TEST_HOST //try to get value.
  29. Then start your applications.

Acknowledgement

This program is forked from embulk-input-ftp and originally written by @frsyuki, modified by @sakama.