shell脚本上传文件到ftp及I won't open a connection to xxx -- only to xxx错误

本文详细介绍了在使用shell脚本通过FTP上传文件时遇到的“Iwon'topenaconnectionto”错误及其解决方案。错误源自FTP服务器拒绝了来自特定IP地址的连接请求,通过将FTP工作模式从主动模式切换到被动模式,成功解决了这一问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ftp上传文件到服务器

/home/androidhotfix/hotfix-soft/inetutils/bin/ftp -p -niv <<- EOF  
open 101.71.xxx.xxx
user dxy XXXXXXXXX
binary
cd /aspirin/hotfix/$patchTypeNamePath
put $patchFileName $patchFileName
put $patchInfoName $patchInfoName
bye  
EOF

如果配置了path,/home/androidhotfix/hotfix-soft/inetutils/bin/ftp 可以直接改成ftp
-p参数可以去掉,那么使用默认ftp工作方式 

shell脚本上传文件到ftp及I won't open a connection to xxx -- only to xxx错误

自动连接上传文件到ftp服务器脚本异常

Connected to 101.71.xxx.xxx.
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 14:36. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
Remote system type is UNIX.
Using binary mode to transfer files.
331 User aspirin OK. Password required
230 OK. Current restricted directory is /
200 TYPE is now 8-bit binary
250 OK. Current directory is /aspirin/hotfix/release
500 I won't open a connection to 192.168.xxx.xxx (only to 101.68.xxx.xxx)
/home/androidhotfix/hotfix-soft/inetutils/bin/ftp: bind: Address already in use
500 I won't open a connection to 192.168.xxx.xxx (only to 101.68.xxx.xxx)
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.

解决方案

由ftp主动模式切换到被动模式 

由 

...
ftp -p -niv <<- EOF  
...

改成 

...
ftp -niv <<- EOF  
...

参考Getting “I won't open a connection to” when connecting to FTP server from Google Compute Engine

补充知识

关于FTP主动模式与被动模式的一点理解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值