linux脚本来自动执行ftp操作 [英] linux script to automate ftp operation

查看:931
本文介绍了linux脚本来自动执行ftp操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的shell脚本是:



我的Linux服务器上的文件传输到FTP服务器。

 #! / bin / ksh 

HOST ='my_ip'
USER ='userid'
PASSWD ='密码'
FILE ='file.txt'
DIREC ='/ eir_log'
ftp -in $ HOST<< EOMYF
用户$ USER $ PASSWD
二进制
mkdir $ DIREC
cd $ DIREC
pwd
退出
EOMYF

非常简单的代码。但问题是虽然我正好登录FTP服务器,但它不允许我在FTP服务器中创建一个新目录。起初,我认为我的脚本有一些错误,但即使单独运行一个 mkdir 在ftp服务器中显示创建目录失败
有人可以让我知道可能的错误,或者如果我的代码中有任何错误,我错过了。 pwd 工作正常,但这意味着通过脚本登录ftp站点是没有问题的。



预先感谢您的帮助

解决方案

查看期望



$ / b>
$ b

 #!/ usr / bin / expect 

set timeout 120
spawn ftp 192.168.0.210
期望名称
发送root \r
期望密码:
发送pass\r
期望ftp>
发送bye \r


I need to transfer a file from my linux server to a FTP server.

My shell script is :

    #! /bin/ksh

    HOST='my_ip'
    USER='userid'
    PASSWD='password'
    FILE='file.txt'
    DIREC='/eir_log'
    ftp -in $HOST << EOMYF 
    user $USER $PASSWD
    binary
    mkdir $DIREC 
    cd $DIREC
    pwd
    quit
    EOMYF

pretty simple code. but the problem is though I am logging in the FTP server fine, but its not allowing me to create a new directory in the FTP server. At first i thought some error with my script, but even individually if i run a mkdir in the ftp server its showing create directory failed. Can somebody let me know the possible error, or if any eror in my code that i am missing out on.The pwd is working fine though, which means there is no problem loging in the ftp site through script.

Thanks in advance for your help

解决方案

Have a look at expect

Something to get you started

#!/usr/bin/expect

set timeout 120
spawn ftp 192.168.0.210
expect "Name"
send "root\r"
expect "Password:"
send "pass\r"
expect "ftp> "
send "bye\r"

这篇关于linux脚本来自动执行ftp操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆