Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

shell - linux script to automate ftp operation

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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
"
expect "Password:"
send "pass
"
expect "ftp> "
send "bye
"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...