Created
February 20, 2026 20:41
-
-
Save hugoarnal/669974117219b5af0eaa080321c1ff2c to your computer and use it in GitHub Desktop.
ftppasv
This file contains hidden or 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
| #!/usr/bin/env bash | |
| ## Calculate the PASV port of an FTP server | |
| ## | |
| ## Example: | |
| ## ./ftppasv "227 Entering Passive Mode (0,0,0,0,148,75)" | |
| ## ./ftppasv 148 75 | |
| ## | |
| ## Automatically calculate 148 * 256 + 75. | |
| ## Should echo "37963" | |
| if [ $# -eq 0 ]; then | |
| echo "No arguments passed" | |
| exit 1 | |
| fi | |
| calculate_port() | |
| { | |
| echo "$(( $1 * 256 + $2 ))" | |
| } | |
| ## "227 Entering Passive Mode (0,0,0,0,148,75)" | |
| if [ $# -eq 1 ]; then | |
| P1=$(echo "$1" | cut -d ',' -f 5) | |
| P2=$(echo "$1" | cut -d ',' -f 6 | cut -d ')' -f 1) | |
| if [[ "$P1" == "" || "$P2" == "" || "$P1" == "$1" || "$P2" == "$1" ]]; then | |
| echo "Invalid argument" | |
| exit 1 | |
| fi | |
| calculate_port $P1 $P2 | |
| fi | |
| ## 148 75 | |
| if [ $# -eq 2 ]; then | |
| calculate_port $1 $2 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment