Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Marketplace Contribution] FTP #35177

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Packs/FTP/.pack-ignore
Empty file.
Empty file added Packs/FTP/.secrets-ignore
Empty file.
87 changes: 87 additions & 0 deletions Packs/FTP/Integrations/FTP/FTP.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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:

Check failure on line 17 in Packs/FTP/Integrations/FTP/FTP.py

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Ruff (S321)

Packs/FTP/Integrations/FTP/FTP.py:17:18: S321 FTP-related functions are being called. FTP is considered insecure. Use SSH/SFTP/SCP or some other encrypted protocol.
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:

Check failure on line 30 in Packs/FTP/Integrations/FTP/FTP.py

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Ruff (S321)

Packs/FTP/Integrations/FTP/FTP.py:30:18: S321 FTP-related functions are being called. FTP is considered insecure. Use SSH/SFTP/SCP or some other encrypted protocol.
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:

Check failure on line 51 in Packs/FTP/Integrations/FTP/FTP.py

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Ruff (S321)

Packs/FTP/Integrations/FTP/FTP.py:51:18: S321 FTP-related functions are being called. FTP is considered insecure. Use SSH/SFTP/SCP or some other encrypted protocol.
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:

Check failure on line 68 in Packs/FTP/Integrations/FTP/FTP.py

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

Ruff (S321)

Packs/FTP/Integrations/FTP/FTP.py:68:18: S321 FTP-related functions are being called. FTP is considered insecure. Use SSH/SFTP/SCP or some other encrypted protocol.
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()
62 changes: 62 additions & 0 deletions Packs/FTP/Integrations/FTP/FTP.yml
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)
7 changes: 7 additions & 0 deletions Packs/FTP/Integrations/FTP/FTP_description.md
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.
Binary file added Packs/FTP/Integrations/FTP/FTP_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions Packs/FTP/Integrations/FTP/README.md
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 added Packs/FTP/README.md
Empty file.
21 changes: 21 additions & 0 deletions Packs/FTP/pack_metadata.json
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"
]
}
Loading