LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-31-2012, 05:23 AM   #1
y0_gesh
LQ Newbie
 
Registered: Nov 2011
Posts: 11

Rep: Reputation: Disabled
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

Last edited by y0_gesh; 01-31-2012 at 05:27 AM.
 
Old 01-31-2012, 05:32 AM   #2
jv2112
Member
 
Registered: Jan 2009
Location: New England
Distribution: Arch Linux
Posts: 719

Rep: Reputation: 106Reputation: 106
Lightbulb

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
 
Old 01-31-2012, 11:55 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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"

Last edited by Dark_Helmet; 01-31-2012 at 03:41 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 05:39 AM
Bash script to read .txt files on a remote Windows 2003 R2 server via FTP laurens Linux - Newbie 25 05-15-2009 06:01 AM
ftp bash script idgeitman Linux - Newbie 1 04-29-2008 04:03 PM
How to connect to ftp using script kmalla Red Hat 7 08-15-2006 10:33 AM
bash script AND ftp bokini Linux - General 2 01-04-2006 04:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration