LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   need a bash script to connect to ftp server. (https://www.linuxquestions.org/questions/programming-9/need-a-bash-script-to-connect-to-ftp-server-926700/)

y0_gesh 01-31-2012 05:23 AM

need a bash script to connect to ftp server.
 
hello guys. i badly need some help here. I need a bash script that connects to an ftp server to get and memorize a list of folders in the directory.

ps : i've already written one that connects to the ftp server and can even send some files.

This is an example of my script
Quote:

ftp -inv <<EOF
open xxx.xxx.xx.xx
user USERNAME PASSWORD
lcd /root/xxx
cd /root/xxx/xxxx
binary
put xxx.txt
quit
EOF

jv2112 01-31-2012 05:32 AM

If you are looking to syncronize files across machines I would recomend rsync. You can use it in combinaion with ssh for a secure connection.


This will "memorize folders" and only sync files that have changed.

http://rsync.samba.org/documentation.html

Dark_Helmet 01-31-2012 11:55 AM

The most common way I have seen to automate/script use of a program that is interactive (e.g. asks for a password, provides a command prompt, etc.) is to use expect. You can make a standalone expect script or you can embed an expect script within a bash script. For instance:

Code:

#!/bin/bash

echo "Bash script about to invoke ftp with expect"

/bin/cat << EOF | /usr/bin/expect
spawn /usr/bin/ftp

expect "ftp> "
send "open\r"

expect "(to) "
send "xxx.xxx.xx.xx\r"

# and so on

interact
EOF

echo "Bash script call to ftp through expect complete. Continuing with additional processing"



All times are GMT -5. The time now is 03:54 PM.