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 02-13-2011, 11:34 AM   #1
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Question two consecutive statements in FTP script


Hi All,

I have made a shell script to copy and delete files through FTP.

I want to first delete all txt files and then mput all txt files.

Code:
ftp ()
{
cd $LOCAL
ftp -in << ENDOFFTP
open $2
user $3 $4
binary
prompt
cd $REMOTE
mdelete *.txt
mput *.txt
close
bye
ENDOFFTP
}
This only deletes all files, "mput" statement is somehow ignored.
If I remove "mdelete *.txt" line "mput" statement works well.

Any idea, how to get through this ?
 
Old 02-13-2011, 11:40 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Remember: "*.txt" has a script metacharacter in it

Try single-quoting the "mdelete" and "mput", and see if that helps:

Code:
'mdelete *.txt'
'mput *.txt'
I haven't actually tried it, so I can't guarantee that it'll work.

But to the extent I believe the problem is "metacharacters", I hope it'll at least point you in the right direction.

'Hope that helps .. PSM
 
Old 02-13-2011, 12:01 PM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by paulsm4 View Post
Remember: "*.txt" has a script metacharacter in it

Try single-quoting the "mdelete" and "mput", and see if that helps:

Code:
'mdelete *.txt'
'mput *.txt'

I haven't actually tried it, so I can't guarantee that it'll work.

But to the extent I believe the problem is "metacharacters", I hope it'll at least point you in the right direction.

'Hope that helps .. PSM
Thanks Paulsm,
I tried this, but I am getting the below error
Quote:
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
331 Please specify the password.
230 Login successful.
200 Switching to Binary mode.
Interactive mode on.
250 Directory successfully changed.
?Invalid command
?Invalid command

221 Goodbye.
 
Old 02-13-2011, 12:47 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
OK - what about this:
Code:
mdelete '*.txt'
mput '*.txt'
or this:
Code:
mdelete "*.txt"
mput "*.txt"

Last edited by paulsm4; 02-13-2011 at 12:50 PM.
 
Old 02-14-2011, 11:33 AM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Hi Paul,

I tried these too, no luck.
 
Old 02-14-2011, 03:22 PM   #6
KaosX
LQ Newbie
 
Registered: Feb 2011
Posts: 4

Rep: Reputation: 0
what about using a for loop to avoid the metacharacters entirely? Though it's not a straight up ftp command, so you might have to work over your function a bit? We normally use scp/rsync/ssh etc for moving files around, makes things somewhat easier, but you might be stuck with ftp.

Something like this possibly (untested):
Code:
for i in *.txt; 
  do 
     mput $i
done
 
Old 04-06-2011, 06:39 AM   #7
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Original Poster
Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by KaosX View Post
what about using a for loop to avoid the metacharacters entirely? Though it's not a straight up ftp command, so you might have to work over your function a bit? We normally use scp/rsync/ssh etc for moving files around, makes things somewhat easier, but you might be stuck with ftp.

Something like this possibly (untested):
Code:
for i in *.txt; 
  do 
     mput $i
done
Hi Kaos,

Thanks but I am looking for consecutive commands in ftp.
 
  


Reply

Tags
shell script



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
[SOLVED] script to read and compare two consecutive lines in a file smritisingh03 Linux - Newbie 16 08-28-2012 04:36 AM
Can I use 'if' statements in Expect script? d3funct Programming 3 02-24-2011 03:59 PM
[SOLVED] Shell script to convert values on successive lines into consecutive ranges? kmkocot Programming 5 07-09-2010 10:59 AM
Proper Syntax for If...Then..Else statements with a script kaplan71 Linux - Software 2 11-11-2008 12:44 PM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM

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

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