LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-07-2007, 12:33 PM   #1
Elguapo
Member
 
Registered: Mar 2005
Distribution: FC7
Posts: 42

Rep: Reputation: 15
FTP Bash script


Each day I have to collect and parse several csv files from one of our IDX vendors. Right now the only collection method they offer for this data is via ftp. Instead of manually doing this each day, I would like to automate this task.

when I run the script below, it doesn't log me in. I have tested using the script in conjunction with a .netrc file. But this is impractical seeing as I will be adding new instances of the same cron job a lot.

Here is my current script. Any help with this would be greatly appreciated.

#!/bin/sh
FTP_PASSIVE_MODE=YES; export FTP_PASSIVE_MODE
echo "Lets FTP"
login=$2
password=$3
ftp $1
echo "Connected"
cd $4
get "*.txt"
echo "FTP completed"
 
Old 06-07-2007, 12:35 PM   #2
Dox Systems - Brian
Member
 
Registered: Nov 2006
Posts: 344

Rep: Reputation: 31
BTDT, I believe my solution was to put the login/ftp action info in a text file then redirect it in via stdin. I also remember needing a "!" symbol in the command line. also, note that get should be replaced by "mget"... You may also need another ftp command line option to avoid possible "confirm" messages for each file (depends on version of FTP).
 
Old 06-07-2007, 01:26 PM   #3
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
What you really need is a "here document". Basically, you are telling it to pass everything between a pair of tags into the command that is running. In your case, you would ...

Code:
ftp -i $1 <<EOF
use $2
$3
cd $4
mget *.txt
quit
EOF
Note that EOF can be anything that you want. I changed it a bit to better facilitate getting multiple files as well (ftp -i will not prompt you for a response because of the mget which you will want to use if you are getting all of the txt files in that directory).

To learn more about here documents, check out the Advanced Bash Scripting Guide at The Linux Documentation Project.
 
  


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
FTP in a Bash Shell Script redirection sleepyhomme Programming 2 05-02-2007 11:53 AM
bash script AND ftp bokini Linux - General 2 01-04-2006 04:33 PM
Using BASH script to transfer a file via (s)ftp senther Linux - Newbie 2 07-19-2005 04:47 PM
how to while in a ftp bash script dezeque Programming 3 06-12-2004 04:13 PM
bash script+ftp+ls->var g00ral Programming 1 05-05-2004 06:58 AM

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

All times are GMT -5. The time now is 07:09 PM.

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