forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[Marketplace Contribution] FTP"" (demisto#35200)
* Revert "Revert "[Marketplace Contribution] FTP (demisto#34659) (demisto#35177)" (demisto#35199)" This reverts commit c34a2a4. * added noqa --------- Co-authored-by: RotemAmit <ramit@paloaltonetworks.com>
- Loading branch information
Showing
9 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} |