From 85a9bee513f859aa556e63249e17a1b9cabfd303 Mon Sep 17 00:00:00 2001 From: Dan Tavori <38749041+dantavori@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:03:14 +0300 Subject: [PATCH] Revert "Revert "[Marketplace Contribution] FTP"" (#35200) * Revert "Revert "[Marketplace Contribution] FTP (#34659) (#35177)" (#35199)" This reverts commit c34a2a499fa9babda75a40a273f139cdcf396c0b. * added noqa --------- Co-authored-by: RotemAmit --- Packs/FTP/.pack-ignore | 0 Packs/FTP/.secrets-ignore | 0 Packs/FTP/Integrations/FTP/FTP.py | 85 ++++++++++++++++++ Packs/FTP/Integrations/FTP/FTP.yml | 62 +++++++++++++ Packs/FTP/Integrations/FTP/FTP_description.md | 7 ++ Packs/FTP/Integrations/FTP/FTP_image.png | Bin 0 -> 1853 bytes Packs/FTP/Integrations/FTP/README.md | 79 ++++++++++++++++ Packs/FTP/README.md | 0 Packs/FTP/pack_metadata.json | 21 +++++ 9 files changed, 254 insertions(+) create mode 100644 Packs/FTP/.pack-ignore create mode 100644 Packs/FTP/.secrets-ignore create mode 100644 Packs/FTP/Integrations/FTP/FTP.py create mode 100644 Packs/FTP/Integrations/FTP/FTP.yml create mode 100644 Packs/FTP/Integrations/FTP/FTP_description.md create mode 100644 Packs/FTP/Integrations/FTP/FTP_image.png create mode 100644 Packs/FTP/Integrations/FTP/README.md create mode 100644 Packs/FTP/README.md create mode 100644 Packs/FTP/pack_metadata.json diff --git a/Packs/FTP/.pack-ignore b/Packs/FTP/.pack-ignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/Packs/FTP/.secrets-ignore b/Packs/FTP/.secrets-ignore new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/Packs/FTP/Integrations/FTP/FTP.py b/Packs/FTP/Integrations/FTP/FTP.py new file mode 100644 index 000000000000..87838ffc8e4a --- /dev/null +++ b/Packs/FTP/Integrations/FTP/FTP.py @@ -0,0 +1,85 @@ +import demistomock as demisto # noqa: F401 +from CommonServerPython import * # noqa: F401 +""" IMPORT """ + +from ftplib import FTP + +""" MAIN """ + +def main(): + HOST = demisto.params().get('host') + PORT = demisto.params().get('port') if demisto.params().get('port') else '21' + USER = demisto.params()['credentials']['identifier'] + PASSWD = demisto.params()['credentials']['password'] + + if demisto.command() == "test-module": + try: + with FTP() as ftp: # noqa: S321 + ftp.connect(host=HOST,port=int(PORT)) + ftp.login(user=USER, passwd=PASSWD) + ftp.voidcmd('NOOP') + + demisto.results("ok") + except Exception as excp: + return_error(f"Error occurred - Error: {str(excp)}") + + if demisto.command() == "ftp-ls": + path = demisto.args().get('path') + list_path = path if path else '~/' + try: + with FTP() as ftp: # noqa: S321 + ftp.connect(host=HOST, port=int(PORT)) + ftp.login(user=USER, passwd=PASSWD) + outputs = CommandResults( + outputs_prefix='FTP.List', + outputs={ + 'Files': ftp.nlst(f"{list_path}") + } + ) + return_results(outputs) + + except IndexError: + return_results("There is no file or folder") + except Exception as excp: + return_error(f"Error occurred - Error: {str(excp)}") + + if demisto.command() == "ftp-put": + entry_id = demisto.args().get('entry_id') + target = demisto.args().get('target') + + try: + with FTP() as ftp: # noqa: S321 + ftp.connect(host=HOST, port=int(PORT)) + ftp.login(user=USER, passwd=PASSWD) + fileObject = demisto.getFilePath(entry_id) + with open(fileObject['path'], 'rb') as file: + ftp.storbinary(f'STOR {target}/{fileObject["name"]}', file) + + return_results(f'File uploaded to {target}/{fileObject["name"]} successfully') + + except Exception as excp: + return_error(f"Error occurred - Error: {str(excp)}") + + if demisto.command() == "ftp-get": + file_path = demisto.args().get('file_path') + file_name = demisto.args().get('file_name') + + try: + with FTP() as ftp: # noqa: S321 + ftp.connect(host=HOST, port=int(PORT)) + ftp.login(user=USER, passwd=PASSWD) + with open(f'/tmp/{file_name}', 'wb') as file: + ftp.retrbinary(f'RETR {file_path}/{file_name}', file.write) + + with open(f"/tmp/{file_name}", "r") as f: + data = f.read() + return_results( + fileResult(filename = file_name, data = data) + ) + + except Exception as excp: + return_error(f"Error occurred - Error: {str(excp)}") + + +if __name__ in ("__main__", "__builtin__", "builtins"): + main() diff --git a/Packs/FTP/Integrations/FTP/FTP.yml b/Packs/FTP/Integrations/FTP/FTP.yml new file mode 100644 index 000000000000..67d0c02d2b0e --- /dev/null +++ b/Packs/FTP/Integrations/FTP/FTP.yml @@ -0,0 +1,62 @@ +category: Utilities +commonfields: + id: FTP + version: -1 +configuration: +- display: 'Host' + name: host + required: true + section: Connect + type: 0 +- display: 'Port' + name: port + defaultvalue: "21" + required: false + section: Connect + type: 0 +- display: Username + name: credentials + type: 9 + required: false +- advanced: true + display: Use system proxy settings + name: proxy + required: false + section: Connect + type: 8 +description: 'FTP integration to download or upload files to a remote FTP server. Please note that FTP transfer is insecure. Please use it with care.' +display: FTP +name: FTP +script: + commands: + - arguments: + - description: The path to list. + name: path + description: List all the files under the current folder. + name: ftp-ls + - arguments: + - name: entry_id + required: true + description: The Entry ID of the file to upload. + - name: target + required: true + description: The target FTP server to upload the file to. + description: Upload file to FTP server. + name: ftp-put + - arguments: + - name: file_path + required: true + description: The path to the file to download from the FTP server. + - name: file_name + required: true + description: The file name to download from the FTP server. + description: Download file from FTP server. + name: ftp-get + dockerimage: demisto/python3:3.10.14.96411 + runonce: false + script: '' + subtype: python3 + type: python +fromversion: 6.0.0 +tests: +- No tests (auto formatted) diff --git a/Packs/FTP/Integrations/FTP/FTP_description.md b/Packs/FTP/Integrations/FTP/FTP_description.md new file mode 100644 index 000000000000..554e7812f7b0 --- /dev/null +++ b/Packs/FTP/Integrations/FTP/FTP_description.md @@ -0,0 +1,7 @@ +### Community Integration + +No support or maintenance is provided by the author. Customers are encouraged to engage with the user community for questions and guidance at the [Cortex XSOAR Live Discussions](https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/bd-p/Cortex_XSOAR_Discussions). + +It supports anonymous login. Please input anonymous as username and leave password empty. + +Please be noted that FTP transfer is insecure. Please use it with care. \ No newline at end of file diff --git a/Packs/FTP/Integrations/FTP/FTP_image.png b/Packs/FTP/Integrations/FTP/FTP_image.png new file mode 100644 index 0000000000000000000000000000000000000000..b711deacd0e2d17e33bb8d305ef0a3916b760120 GIT binary patch literal 1853 zcmeAS@N?(olHy`uVBq!ia0vp^6+mpn!3HF!FPFc;z`z)p>FgZf>Flf!P?VpRnUl)E zpfRy@g0(lZqe$!dER#pOH(XAVc2wPGrnzO3L?BDIfT(Cg43{L`UDVvZ{%m!< z`@1P>%VIue1D~|d2^Kc4Vm0Saox1NB{CQjWTOsG>bl>*t=DP0dy_L0-r`P`#4VB-V z+$`YQ%zpCgymlj?^n$=WuNoza^=oR*KYd1Pk*3v&NuO&%BrWf zWq0y-+?l|dRkpNdHuIjl4iDo_eP1)Bm3hH0PK)#POfgfFm+Z*1@&|@>SZai4ny)W| z7Ld)sz}TM2zyf430KU*`2*hK{El7hdn?5Gq21*@saol-r z^INOEn}45kn6i2E|GCfq7t7DTJ5{FnU;>lSw$g-y+mt6a?zL2C$o=OgaDeH?Grk)& z6-8{^3A3#eK0may>{)*`%W?5VgR7^`o#Sh9Qe1I0YgtL!+c{oK6=t73^z^Cfl+#Zm zRpX2J+L`D0sq5(J9lCT$Xvf_=j`qVFHg06Rm?83~?*H_vQ{p-d_BJ*S`|q2Zp4+|K z`a^}yveGou##<7LFP_+9cgSBwsGy*LVWLOMwTI7UO+No%=dG1uvwhSqye)h9E?ZLV*f9H%$q zy}Nf?lQ#Z%yyN@#@20oUpF6i8YHil1%bk1o+G>b!UCunb{$uaNlPOagJ{nEbO6giw z^ewi$vNF;#^f8aKDASBnH~n|ruU%6!h2sIgdd{!kPoK8tq!h7Djy&xg!SJ7veNXn+ z^-c`J*8P{?KYskU-#s#7!Qq6Jrgm9HJXQ7&E>mu=Z?ePxbSUi4O7KFY8`lfd})wpd2rnN@bb6$+%MJs z-!J=^h&+hUSymI{ z@oq*R^8?`}{VTwe41r9fw8PrUs zH*aBh=Fqr-ozW*lk3Ey|Oe0ewKhum0F?^SpW-zlJl4CJgxKm~cs{uP#i!DcjQ?aE7 zcLJXXN43C#mS;s1#16=42z*m$;5_?O;q8R~W~UjMWBH5NE?1s*ie%V)z~Ooe!?MrQ bT0dzswyo$`T;?SXDlR=;{an^LB{Ts5_yYYw literal 0 HcmV?d00001 diff --git a/Packs/FTP/Integrations/FTP/README.md b/Packs/FTP/Integrations/FTP/README.md new file mode 100644 index 000000000000..399a3de731e6 --- /dev/null +++ b/Packs/FTP/Integrations/FTP/README.md @@ -0,0 +1,79 @@ +FTP integration to download or upload files to a remote FTP server. Please note that FTP transfer is insecure. Please use it with care. + +## Configure FTP on Cortex XSOAR + +1. Navigate to **Settings** > **Integrations** > **Servers & Services**. +2. Search for FTP. +3. Click **Add instance** to create and configure a new integration instance. + + | **Parameter** | **Required** | + | --- | --- | + | Host | True | + | Port | False | + | Username | False | + | Password | False | + | Use system proxy settings | False | + +4. Click **Test** to validate the URLs, token, and connection. + +## Commands + +You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook. +After you successfully execute a command, a DBot message appears in the War Room with the command details. + +### ftp-ls + +*** +List all the files under the current folder. + +#### Base Command + +`ftp-ls` + +#### Input + +| **Argument Name** | **Description** | **Required** | +| --- | --- | --- | +| path | The path to list. | Optional | + +#### Context Output + +There is no context output for this command. +### ftp-put + +*** +Upload file to FTP server. + +#### Base Command + +`ftp-put` + +#### Input + +| **Argument Name** | **Description** | **Required** | +| --- | --- | --- | +| entry_id | The Entry ID of the file to upload. | Required | +| target | The target FTP server to upload the file to. | Required | + +#### Context Output + +There is no context output for this command. +### ftp-get + +*** +Download file from FTP server. + +#### Base Command + +`ftp-get` + +#### Input + +| **Argument Name** | **Description** | **Required** | +| --- | --- | --- | +| file_path | The path to the file to download from the FTP server. | Required | +| file_name | The file name to download from the FTP server. | Required | + +#### Context Output + +There is no context output for this command. diff --git a/Packs/FTP/README.md b/Packs/FTP/README.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/Packs/FTP/pack_metadata.json b/Packs/FTP/pack_metadata.json new file mode 100644 index 000000000000..072217ac900d --- /dev/null +++ b/Packs/FTP/pack_metadata.json @@ -0,0 +1,21 @@ +{ + "name": "FTP", + "description": "FTP integration to download or upload file to remote ftp server. Please be noted that FTP transfer is insecure. Please use it with care. ", + "support": "community", + "currentVersion": "1.0.0", + "author": "Jie Liau", + "url": "", + "email": "", + "created": "2024-06-01T06:43:37Z", + "categories": ["Utilities"], + "tags": [], + "useCases": [], + "keywords": [], + "marketplaces": [ + "xsoar", + "marketplacev2" + ], + "githubUser": [ + "jieliau" + ] +} \ No newline at end of file