服务器到服务器文件传输端口?

我使用bash脚本(https://github.com/johnnywoof/FTP-Bash-Backup)将我的Debian www目录备份到ftp服务器。一切顺利,但传输被防火墙阻止。每次使用单独的端口的脚本,所以我不能通过防火墙解除阻止。有什么方法可以指定一个端口?服务器到服务器文件传输端口?

的bash脚本

# FTP server settings 

USERNAME=""

PASSWORD=""

SERVER=""

PORT=21

BACKUPDIR="/"

ndays=7

LOCAL_DIRECTORY="/home"

TEMP_BACKUP_STORE="/tmp"

ENCRYPT_BACKUP=false

AES_PASSWORD_FILE=""

timestamp=$(date --iso)

backup_remote_file_name="$timestamp.tar.gz"

backup_file="$TEMP_BACKUP_STORE/$backup_remote_file_name"

MM=`date --date="$ndays days ago" +%b`

DD=`date --date="$ndays days ago" +%d`

echo "Removing files older than $MM $DD"

listing=`ftp -i -n $SERVER $PORT <<EOMYF

user $USERNAME $PASSWORD

binary

cd $BACKUPDIR

ls

quit

EOMYF`

lista=($listing)

for ((FNO=0; FNO<${#lista[@]}; FNO+=9));do

# month (element 5), day (element 6) and filename (element 8)

#echo Date ${lista[`expr $FNO+5`]} ${lista[`expr $FNO+6`]} File: ${lista[`expr $FNO+8`]}

if [ ${lista[`expr $FNO+5`]}=$MM ];

then

if [[ ${lista[`expr $FNO+6`]} -lt $DD ]];

then

echo "Removing ${lista[`expr $FNO+8`]}"

ftp -i -n $SERVER $PORT <<EOMYF2

user $USERNAME $PASSWORD

binary

cd $BACKUPDIR

delete ${lista[`expr $FNO+8`]}

quit

EOMYF2

fi

fi

done

echo "Creating backup..."

tar -czf $backup_file $LOCAL_DIRECTORY

if [ "$ENCRYPT_BACKUP" == "true" ]

then

echo "Encrypting backup using OpenSSL..."

output_encrypted_file="$backup_file.enc"

openssl enc -aes-256-cbc -salt -in $backup_file -out $output_encrypted_file -pass file:$AES_PASSWORD_FILE

rm $backup_file

backup_file=$output_encrypted_file

fi

echo "Uploading backup $backup_file ..."

ftp -n -i $SERVER $PORT <<EOF

user $USERNAME $PASSWORD

cd $BACKUPDIR

put $backup_file $backup_remote_file_name

quit

EOF

echo "Deleting temporary files..."

rm $backup_file

echo "Backup complete."

回答:

切换到被动模式:

插入passive在新行后user命令。


参见:Active FTP vs. Passive FTP, a Definitive Explanation

以上是 服务器到服务器文件传输端口? 的全部内容, 来源链接: utcz.com/qa/260199.html

回到顶部