Skip to content

Commit 151ac27

Browse files
author
Soumyanjan Dey
committed
Initial version released
0 parents  commit 151ac27

File tree

6 files changed

+221
-0
lines changed

6 files changed

+221
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# FTP Swift
2+
3+
## Overview
4+
5+
FTP Swift is a fast and reliable solution for uploading and managing files and folders via FTP. It ensures seamless transfers with secure connections, making file management efficient and hassle-free.
6+
7+
## Features
8+
9+
- Automatic FTP deployment on GitHub push
10+
- Secure and efficient file transfers
11+
- Customizable local and remote directory settings
12+
- Supports GitHub Actions for CI/CD integration
13+
14+
## Usage
15+
16+
This setup uses GitHub Actions to automatically deploy your files and folders via FTP when changes are pushed to the specified branch.
17+
18+
### Workflow Configuration
19+
20+
The following GitHub Actions workflow (`.github/workflows/<any_file_name>.yml`) is used to deploy files via FTP:
21+
22+
```yaml
23+
name: Deploy website
24+
on:
25+
push:
26+
branches: [<your_branch_name>]
27+
28+
jobs:
29+
deploy:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Run Custom FTP Deploy
36+
uses: arwebcs/FTP-Swift@v1.0.0
37+
with:
38+
server: ${{ secrets.FTP_HOST }}
39+
username: ${{ secrets.FTP_USERNAME }}
40+
password: ${{ secrets.FTP_PASSWORD }}
41+
port: ${{ secrets.FTP_PORT }}
42+
local-dir: ""
43+
remote-dir: ""
44+
```
45+
46+
## Setup Instructions
47+
48+
1. **Create GitHub Secrets:**
49+
50+
- Go to your repository settings on GitHub.
51+
- Navigate to **Secrets and variables** > **Actions**.
52+
- Add the following secrets:
53+
54+
2. **Configure FTP Server Details:**
55+
56+
- Update the `local-dir` and `remote-dir` fields in the workflow file as needed.
57+
58+
3. **Commit and Push Changes:**
59+
60+
- Ensure the `.github/workflows/<any_file_name>.yml` file is added to your repository.
61+
- Push your code to the specified branch to trigger the deployment.
62+
63+
## Environment Variables
64+
65+
The following environment variables must be set up as GitHub Secrets for the FTP deployment to work properly:
66+
67+
| Variable | Mandatory | Default Value | Description |
68+
| ------------ | --------- | ------------------------------- | ------------------------------------------------------ |
69+
| FTP_HOST | ✅ Yes | N/A | The hostname or IP address of the FTP server. |
70+
| FTP_USERNAME | ✅ Yes | N/A | The username used to authenticate with the FTP server. |
71+
| FTP_PASSWORD | ✅ Yes | N/A | The password for the FTP user account. |
72+
| FTP_PORT | ❌ No | For non-SSL : 21, For SSL : 990 | The port used for the FTP connection. |
73+
74+
## Support
75+
76+
For issues and feature requests, please open an issue on the repository:
77+
[GitHub Issues](https://github.com/arwebcs/FTP-Swift/issues)

action.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "FTP Swift"
2+
description: "Securely uploads files and folders to an FTP server. Supports authentication, custom ports, and directory selection."
3+
branding:
4+
icon: "upload-cloud"
5+
color: "blue"
6+
author: "Soumyanjan Dey"
7+
8+
inputs:
9+
server:
10+
description: "FTP server address"
11+
required: true
12+
username:
13+
description: "FTP username"
14+
required: true
15+
password:
16+
description: "FTP password"
17+
required: true
18+
port:
19+
description: "FTP port"
20+
required: false
21+
default: "21"
22+
local-dir:
23+
description: "Local directory to upload"
24+
required: false
25+
default: "./"
26+
remote-dir:
27+
description: "Remote directory on FTP server"
28+
required: false
29+
default: "/"
30+
31+
outputs:
32+
status:
33+
description: "Indicates whether the FTP upload was successful or failed."
34+
value: "${{ steps.ftp-upload.outputs.status }}"
35+
uploaded-files:
36+
description: "Comma-separated list of files successfully uploaded to the FTP server."
37+
value: "${{ steps.ftp-upload.outputs.uploaded-files }}"
38+
39+
40+
runs:
41+
using: "composite"
42+
steps:
43+
- name: Install dependencies
44+
run: npm ci --prefix ${{ github.action_path }}
45+
shell: bash
46+
47+
- name: Run FTP Upload
48+
env:
49+
FTP_SERVER: ${{ inputs.server }}
50+
FTP_USERNAME: ${{ inputs.username }}
51+
FTP_PASSWORD: ${{ inputs.password }}
52+
FTP_PORT: ${{ inputs.port }}
53+
LOCAL_DIR: ${{ inputs.local-dir }}
54+
REMOTE_DIR: ${{ inputs.remote-dir }}
55+
run: node ${{ github.action_path }}/index.js
56+
shell: bash
57+
58+

index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const ftp = require("basic-ftp");
2+
3+
async function uploadFiles() {
4+
const client = new ftp.Client();
5+
client.ftp.verbose = true;
6+
7+
const server = process.env.FTP_SERVER;
8+
const username = process.env.FTP_USERNAME;
9+
const password = process.env.FTP_PASSWORD;
10+
const localDir = process.env.LOCAL_DIR || ".";
11+
const remoteDir = process.env.REMOTE_DIR || "/";
12+
13+
const isSSL = server.startsWith("ftps://");
14+
const port = process.env.FTP_PORT
15+
? parseInt(process.env.FTP_PORT, 10)
16+
: isSSL
17+
? 990
18+
: 21;
19+
const secure = isSSL;
20+
21+
const cleanServer = server.replace(/^ftps?:\/\//, "");
22+
23+
console.log(
24+
`Connecting to FTP server: ${cleanServer} on port ${port} (Secure: ${secure})`
25+
);
26+
27+
try {
28+
await client.access({
29+
host: cleanServer,
30+
user: username,
31+
password: password,
32+
secure: secure,
33+
port: port,
34+
});
35+
36+
console.log("Connected! Uploading...");
37+
await client.ensureDir(remoteDir);
38+
await client.uploadFromDir(localDir);
39+
40+
console.log(`Upload successful! Files have been uploaded to: ${remoteDir}`);
41+
} catch (err) {
42+
console.error("FTP Upload failed:", err);
43+
process.exit(1);
44+
} finally {
45+
client.close();
46+
}
47+
}
48+
49+
uploadFiles();

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "ftp-swift",
3+
"version": "1.0.0",
4+
"description": "FTP Swift is a fast and reliable solution for uploading and managing files and folders via FTP. It ensures seamless transfers with secure connections, making file management efficient and hassle-free.",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node index.js"
8+
},
9+
"dependencies": {
10+
"basic-ftp": "^5.0.4"
11+
}
12+
}

0 commit comments

Comments
 (0)