LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-06-2004, 03:37 PM   #1
doctorwebbox
Member
 
Registered: Jun 2003
Location: Rotherham, South Yorkshire, England
Distribution: Debian
Posts: 117

Rep: Reputation: 15
ftp scripting


I can write a script that will log me into an ftp server, navigate locally and remotely, put a file on it and then leave. But trying to build it into a loop so I could transfer several files is proving to be an arsehole. I have been fannying about with it for ages. I think the problem is that anything in my script after sending ftp the quit, bye or exit command doesn't get executed so my loop never reaches it's end.

How do I get my script to carry on going after exiting ftp?
 
Old 12-06-2004, 06:23 PM   #2
Samsara
Member
 
Registered: May 2003
Distribution: Ubuntu, Mac OS X Tiger
Posts: 481

Rep: Reputation: 32
May I cynically ask whether you have considered posting your script?

Samsara
 
Old 12-07-2004, 10:23 AM   #3
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
Try using expect. The expect package comes with a tool called auto-expect which is a great help when writing expect scripts.


Håkan
 
Old 12-07-2004, 12:11 PM   #4
doctorwebbox
Member
 
Registered: Jun 2003
Location: Rotherham, South Yorkshire, England
Distribution: Debian
Posts: 117

Original Poster
Rep: Reputation: 15
Script

This is the script I'm using:

#!/bin/sh
HOST='ftp.blah.blah.blah'
USER='user'
PASSWD='password'
LOCALDIR='/home/user1/ftptestdir/'
REMOTEDIR='/home/user2/ftptestdir/'
cd $LOCALDIR
for i in `ls *.jpg`
do
ftp -n $HOST <<ADAM
quote USER $USER
quote PASS $PASSWD
cd $REMOTEDIR
lcd $LOCALDIR
put $i $i
bye
echo "All done"
done

It never gets as far as echo "All done". Someone has let me know another way of getting the result I am after but I would like to understand why this one doesn't work.
 
Old 12-07-2004, 12:32 PM   #5
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
ADAM is the end marker for the ftp part of the script, so you must put that on its own line after bye. This way you'll get "All done" printed once for each file, not sure if that's what you intended. The other way is to use mput *.jpg. In that case ftp must be started with the -i flag to turn off the confirmation prompt.
 
Old 12-07-2004, 02:10 PM   #6
doctorwebbox
Member
 
Registered: Jun 2003
Location: Rotherham, South Yorkshire, England
Distribution: Debian
Posts: 117

Original Poster
Rep: Reputation: 15
Thanks a lot, that sorted it out. But now I have another problem. This script cannot handle file names with spaces. I have tried everything I can think of, I've tried adding -Q to the ls bit and I've tried putting changing put $1 $1 to put "$1" "$1" but no joy. Can you tell me what I'm doing wrong?
 
Old 12-07-2004, 04:40 PM   #7
Samsara
Member
 
Registered: May 2003
Distribution: Ubuntu, Mac OS X Tiger
Posts: 481

Rep: Reputation: 32
You may find perl more flexible:
Code:
#!/usr/bin/perl -w

my $username = "foobar";
my $password = "secret";
my $remote_dir = "public";
my $remote_log_dir = "../logs";

my $local_dir = "/home/user/upload/";
my $local_log_dir = "/home/user/logs/";
chomp (my @localfiles = `ls $local_dir`);

use Net::FTP;

my $ftp = Net::FTP->new("mysite.org") || die "Can't connect: $@\n";
$ftp -> login($username, $password) || die "Couldn't login.";
$ftp -> cwd($remote_dir);
my @remotefiles = ($ftp -> ls);
print "@remotefiles\n";

foreach (@localfiles) {
        $ftp->put($local_dir.$_);
}

# now fetch the logfiles
$ftp -> cwd($remote_log_dir);
my @logfiles = ($ftp -> ls);

foreach (@logfiles) {
       $ftp->get($_, $local_log_dir.$_);
}

# and quit
$ftp->quit;
 
Old 01-21-2005, 12:01 PM   #8
dotc
LQ Newbie
 
Registered: May 2004
Location: Dallas
Posts: 14

Rep: Reputation: 0
fetch new files

Hi:
I have this strange problem. I want to just fetch newer files from the remote ftp server. I have automated the ftp login script. It logs in beautifully but then to check whether the file is new and just get the newer files is still a challenge. I want to know like is there anyway i can run a shell script on the remote server using ftp. By the way remote ftp server is owned by us and is a Linux SuSE 9.0. Any help in this direction will be appreciated.
thanks a lot
Chet
U T Dallas
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp server - Pure ftp - logs in OK but no files visible tp11235 Linux - Networking 2 08-30-2005 05:11 AM
FTP Server Up and running... how do I hide ftp users from local login screen? joe1031 Mandriva 2 03-18-2005 04:24 PM
problem with ftp on mandrake 10.1 Official, ftp speeds system wide (anybody noticed?) equinox Mandriva 15 11-10-2004 02:07 PM
Scripting of routine ftp download BioHak Linux - Newbie 0 03-02-2003 08:17 PM
how can I restrict ftp users listing files from a pure-ftp server adrianmak Linux - Networking 2 12-31-2002 08:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:35 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