- 论坛徽章:
- 0
|
本帖最后由 sunshinelzy 于 2012-07-24 18:04 编辑
BK_DR=/mnt/hgfs/MyTools/FTP #备份文件存放路径
echo "----------开始连接----------"
##连接ftp服务器,21为ftp端口##
ftp -pinevd 192.168.72.8 21 <<!
user root 123456
#prompt off
cd $BK_DR
pwd
passive auto
ls .
cd $BK_DR
mdelete aaa.tar
close
bye
!
环境为VM虚拟机7.1
红帽9.0 和 红帽6.0workstation
无论是在哪台上执行 都是报550的错误
如果是手打命令则正常无错误
再附上环境下载地址
红帽9 红帽9.0
红帽6 [红帽企业Linux.6.0.桌面版].rhel-workstation-6.0-i386-dvd.iso
求解答
附上调试信息
[root@localhost FTP]# sh *.sh
: command not found
: command not found
: command not found
: command not found
--------------------
Connected to 192.168.72.8 (192.168.72. .
220 (vsFTPd 2.2.2)
---> SYST
530 Please login with USER and PASS.
---> USER root
331 Please specify the password.
---> PASS XXXX
230 Login successful.
?Invalid command
?Invalid command
---> CWD /mnt/hgfs/MyTools/FTP
250 Directory successfully changed.
?Invalid command
?Invalid command
Passive mode off.
---> PORT 192,168,72,8,204,218
200 PORT command successful. Consider using PASV.
---> LIST .
150 Here comes the directory listing.
-rwxrwxrwx 1 0 0 0 Jul 23 06:54 aaa.tar
-rwxrwxrwx 1 0 0 497 Jul 23 06:56 ftp.sh
226 Directory send OK.
---> CWD /mnt/hgfs/MyTools/FTP
250 Directory successfully changed.
---> PORT 192,168,72,8,138,54
---> NLST aaa.tar
---> DELE aaa.tar
550 Delete operation failed.
?Invalid command
?Invalid command
?Invalid command
---> QUIT
221 Goodbye.
: command not found
脚本为Vi编写 不存在^M符号
附上cat -A- [root@localhost FTP]# cat -A ftp.sh
- #!/bin/bash -x^M$
- BK_DR=/mnt/hgfs/MyTools/FTP^M$
- ^M$
- ^M$
- ^M$
- username=root^M$
- password=123456^M$
- ^M$
- ftp -pinevd 192.168.72.8 21 <<!^M$
- user root 123456^M$
- #prompt off^M$
- cd $BK_DR^M$
- pwd^M$
- passive auto^M$
- ls .^M$
- cd $BK_DR^M$
- mdelete aaa.tar^M$
- close^M$
- bye^M$
- !^M$
- ^M$
复制代码 这里的^M用 %s/ctrl+v ctrl+m//g 无法识别到 因此我个人认为并不是windows下的那个^M符号- [root@localhost FTP]# sh ftp.sh
- : command not found
- : command not found
- : command not found
- : command not found
- Connected to 192.168.72.8 (192.168.72.8).
- 220 (vsFTPd 2.2.2)
- ---> SYST
- 530 Please login with USER and PASS.
- ---> USER root
- 331 Please specify the password.
- ---> PASS XXXX
- 230 Login successful.
- ?Invalid command
- ---> CWD /mnt/hgfs/MyTools/FTP
- 250 Directory successfully changed.
- ?Invalid command
- Passive mode off.
- ---> PORT 192,168,72,8,222,112
- 200 PORT command successful. Consider using PASV.
- ---> LIST .
- 150 Here comes the directory listing.
- -rwxrwxrwx 1 0 0 0 Jul 23 06:54 aaa.tar
- -rwxrwxrwx 1 0 0 230 Jul 23 09:56 ftp.sh
- -rwxrwxrwx 1 0 0 208 Jul 23 12:48 n.sh
- 226 Directory send OK.
- ---> CWD /mnt/hgfs/MyTools/FTP
- 250 Directory successfully changed.
- ---> PORT 192,168,72,8,197,78
- ---> NLST aaa.tar
- ---> DELE aaa.tar
- 550 Delete operation failed.
- ?Invalid command
- ?Invalid command
- ---> QUIT
- 221 Goodbye.
- : command not found
复制代码 再说明下 如果认为^M$是这个问题
我可以肯定不是 2份代码都附上执行过程了 并不解决问题
我用cat -A ftp.sh > n.sh
重新生成 再把所有的都去掉了
依然还有问题- [root@localhost FTP]# cat -A n.sh
- #!/bin/bash -x$
- BK_DR=/mnt/hgfs/MyTools/FTP$
- $
- $
- username=root$
- password=123456$
- $
- ftp -pinevd 192.168.72.8 21 <<!$
- user root 123456$
- #prompt off$
- cd $BK_DR$
- pwd$
- passive auto$
- ls .$
- cd $BK_DR$
- mdelete aaa.tar$
- close$
- bye$
- !$
- $
复制代码 附上执行过程- [root@localhost FTP]# bash -vx n.sh
- #!/bin/bash -x
- BK_DR=/mnt/hgfs/MyTools/FTP
- + BK_DR=/mnt/hgfs/MyTools/FTP
- username=root
- + username=root
- password=123456
- + password=123456
- ftp -pinevd 192.168.72.8 21 <<!
- user root 123456
- #prompt off
- cd $BK_DR
- pwd
- passive auto
- ls .
- cd $BK_DR
- mdelete aaa.tar
- close
- bye
- !
- + ftp -pinevd 192.168.72.8 21
- Connected to 192.168.72.8 (192.168.72.8).
- 220 (vsFTPd 2.2.2)
- ---> SYST
- 530 Please login with USER and PASS.
- ---> USER root
- 331 Please specify the password.
- ---> PASS XXXX
- 230 Login successful.
- ?Invalid command
- ---> CWD /mnt/hgfs/MyTools/FTP
- 250 Directory successfully changed.
- ---> PWD
- 257 "/mnt/hgfs/MyTools/FTP"
- Passive mode off.
- ---> PORT 192,168,72,8,238,14
- 200 PORT command successful. Consider using PASV.
- ---> LIST .
- 150 Here comes the directory listing.
- -rwxrwxrwx 1 0 0 0 Jul 23 06:54 aaa.tar
- -rwxrwxrwx 1 0 0 230 Jul 23 09:56 ftp.sh
- -rwxrwxrwx 1 0 0 208 Jul 23 12:48 n.sh
- 226 Directory send OK.
- ---> CWD /mnt/hgfs/MyTools/FTP
- 250 Directory successfully changed.
- ---> PORT 192,168,72,8,135,122
- ---> NLST aaa.tar
- ---> DELE aaa.tar
- 550 Delete operation failed.
- ---> QUIT
- 221 Goodbye.
复制代码 |
|