LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-20-2006, 02:01 PM   #1
javier_ccs
Member
 
Registered: Apr 2005
Location: Milton Keynes
Distribution: ubuntu 12.10
Posts: 87

Rep: Reputation: 15
Unhappy shell script for ftp


hello friends,


i need to make a script that using ftp copies al .txt files on /tmp/folder/from machine A (10.0.0.1) to machine B (10.0.0.2) on /tmp/folderb/ using shell...

so far this is what i've done:

#!/bin/sh
HOST='10.0.0.2'
USER='user'
PASSWD='pw'
FILE='/tmp/folder/.txt'

ftp $HOST
user $USER
$PASSWD
put $FILE
quit
exit 0

as u can imagine, it doesn't work because i don't know how to specify that it should grab all .txt

and then again i don't know how to indicate that it should put it on /tmp/folderb/
 
Old 06-20-2006, 02:51 PM   #2
kaz2100
Senior Member
 
Registered: Apr 2005
Location: Penguin land, with apple, no gates
Distribution: Debian testing woody(32) sarge etch lenny squeeze(+64) wheezy jessie
Posts: 1,436

Rep: Reputation: 83
It seems that you have your own isolated network. NFS mount and copy or even using r-command may be easier.
 
Old 06-20-2006, 02:55 PM   #3
javier_ccs
Member
 
Registered: Apr 2005
Location: Milton Keynes
Distribution: ubuntu 12.10
Posts: 87

Original Poster
Rep: Reputation: 15
i guess, but the thing is that i was hoping to create the script and the add it to cron since it should run every day at 23:00
 
Old 06-20-2006, 06:51 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,095

Rep: Reputation: 493Reputation: 493Reputation: 493Reputation: 493Reputation: 493
Two easy ways to do this:

1) ncftput (it is part of the ncftp package)
I think it does exactly what you need.

2) use netcat:
Code:
cat $FTP_SCRIPT | netcat $HOST 21
The $FTP_SCRIPT should be the name of a file, containing:
Code:
user myuser
pass mypass
put myfile1
put myfile2
etc...
quit
You can embed the contents of this file in your script as a single string and do:
Code:
echo $FTP_STRING | netcat $HOST 21
but then you have to embed CRLF characters in your string. That can be awkward to do sometimes, especially if you use joe as editor.

Method 1 is the best for simple problems.

jlinkels
 
Old 06-20-2006, 06:57 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Or even use rsync :-)
 
Old 06-20-2006, 09:36 PM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 114Reputation: 114
or scp. If you run ssh-agent (via keychain is best) then you can specify certificate credentials which will eliminate the need to log in to the destination machine. Then it is just this simple:

cd /tmp
scp * user@destmachine:/tmp/*
 
Old 07-18-2006, 02:36 PM   #7
paul.anderson
LQ Newbie
 
Registered: Jul 2006
Posts: 3

Rep: Reputation: 0
Shell script for ftp

If both machines are *nix based I would suggest using scp (secure copy). It is by far the best way to transferr files. Check to man pages on scp. If not try something like this in your script:

ftp -i -v -n <<FTP_END
open 10.0.0.1
user username password
passive # if needed
cd /whatever/directory
mput *.txt
bye
FTP_END
 
Old 07-18-2006, 11:02 PM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
FYI, rsync has a 'use ssh' option, and only txfrs file differences, useful if copying large files.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Auto ftp shell script mcrosby Linux - Newbie 9 06-27-2007 06:09 AM
Syncronizing folders through ftp shell script mcrosby Linux - General 12 06-01-2006 02:09 AM
Automating FTP upload via a shell script? Spitty Programming 5 01-16-2006 10:28 PM
Trouble when automating ftp with shell script hari_s_82 Linux - Newbie 2 09-23-2004 02:17 AM
How to Shell Script auto ftp connection? mtn356 Linux - General 4 03-18-2004 07:31 PM


All times are GMT -5. The time now is 12:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration