LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   two consecutive statements in FTP script (https://www.linuxquestions.org/questions/programming-9/two-consecutive-statements-in-ftp-script-862421/)

vikas027 02-13-2011 11:34 AM

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 ?

paulsm4 02-13-2011 11:40 AM

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

vikas027 02-13-2011 12:01 PM

Quote:

Originally Posted by paulsm4 (Post 4257003)
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.

paulsm4 02-13-2011 12:47 PM

OK - what about this:
Code:

mdelete '*.txt'
mput '*.txt'

or this:
Code:

mdelete "*.txt"
mput "*.txt"


vikas027 02-14-2011 11:33 AM

Hi Paul,

I tried these too, no luck. :(

KaosX 02-14-2011 03:22 PM

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


vikas027 04-06-2011 06:39 AM

Quote:

Originally Posted by KaosX (Post 4258241)
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.


All times are GMT -5. The time now is 03:52 PM.