-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5763e7a
commit 2180893
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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,42 @@ | ||
from ftplib import FTP | ||
from crewai_tools import tool | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
load_dotenv() | ||
|
||
# FTP server details | ||
ftp_host = os.getenv('FTP_HOST') | ||
ftp_user = os.getenv('FTP_USER') | ||
ftp_p = os.getenv("FTP_PASSWORD") | ||
ftp_path = '/' | ||
|
||
|
||
@tool | ||
def upload_files(file_paths: list[str]): | ||
"""Upload a list of files to the FTP server.""" | ||
|
||
result = True | ||
# Loop through each file path in the list | ||
for file_path in file_paths: | ||
# Establish FTP connection | ||
with FTP(ftp_host) as ftp: | ||
try: | ||
# Login to the server | ||
ftp.login(user=ftp_user, passwd=ftp_p) | ||
print(f"Connected to FTP server: {ftp_host}") | ||
|
||
# Change to the desired directory on the server | ||
ftp.cwd(ftp_path) | ||
|
||
# Open the file in binary mode for reading | ||
with open(file_path, 'rb') as file: | ||
# Upload the file | ||
ftp.storbinary(f'STOR {file_path}', file) | ||
print(f"Successfully uploaded {file_path} to {ftp_path}") | ||
|
||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
result = False | ||
|
||
return result |
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,6 @@ | ||
{ | ||
"name": "ftp", | ||
"package": "", | ||
"env": "FTP_HOST=...\nFTP_USER=...\nFTP_PASSWORD=...", | ||
"tools": ["upload_files"] | ||
} |