1834166 Members
2492 Online
110064 Solutions
New Discussion

need help for ftp script

 
SOLVED
Go to solution
GK_5
Regular Advisor

need help for ftp script

Hi!
I have to write a ftp script in which I have to ftp files from NT (ftp server) to Unix. Verify the files are transferred and then delete the files on NT. I wrote a shell scirpt on Unix. Well the FTP and verification part is working. Now I have to delete the files on Windows box. For this protion I'm using the script as below. But it is not working. Basically it is not taking the inputs between ftp & END for ftp.
Can anyone help?

while read line
do
ftp -n ip / quote USER uname
quote PASS password
bin
cd dir
delete $line
bye
END
done < file_with_filenames_tobe_deleted

Thank you,
IT is great!
14 REPLIES 14
Steven E. Protter
Exalted Contributor

Re: need help for ftp script

try changing /
Thats how i do it.

Maybe just a cut and paste issue, but i never scripted with those slashes.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
GK_5
Regular Advisor

Re: need help for ftp script

Hi! Steve,

It does not work with << in while loop.

Thanks
IT is great!
H.Merijn Brand (procura
Honored Contributor

Re: need help for ftp script

If you mean escapes, the slashes point the wrong way / \<\<

And me neither uses here docs. I use Net::FTP with perl

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
GK_5
Regular Advisor

Re: need help for ftp script

Procura,

When I use the same script and take out the while loop and delete command in ftp and add other command like ls it works.

It is the << charaters that is causing in the while loop not to work.

Thanks
IT is great!
H.Merijn Brand (procura
Honored Contributor

Re: need help for ftp script

WAIT, Hold your horses!!!!

The forum is killing us.


Is the "END" word at the start of the line, or do you have leading spaces?

<< (here documents) need the trailing text, the mark, to be EXACT. No leading spaces, no trailing spaces

Enjoy, Have FUN! H.Merijn [ who hopes to have hit the nail ]
Enjoy, Have FUN! H.Merijn
Marvin Strong
Honored Contributor

Re: need help for ftp script

I too had never had to \ my << for a here doc. That seems strange to me.

The perl module mentioned is also very nice.

my here docs look something like this:

cat <this
is
a
test
EOF

and I have never had any problems doing here docs just like that in loops.
Peter Nikitka
Honored Contributor

Re: need help for ftp script

Hi,

I agree with procura in really checking for spaces...
But if you don't like the here-document or your
shell is in bad mood, use a pipe:

for ..
do
echo "ftp-command
..." | ftp -n ip
done

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
H.Merijn Brand (procura
Honored Contributor

Re: need help for ftp script

--8<--- remove.pl
#!/usr/bin/perl

use Net::FTP;
my $f = Net::FTP->new ("10.10.10.10");
$f->login ("user", "password");
$f->cwd ("dir");

while (<>) {
chomp;
$f->delete ($_);
}
-->8---

# remove.pl files to delete

or

# remove.pl file_with_list_of_files_to_delete

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
GK_5
Regular Advisor

Re: need help for ftp script

Hi! All,
It is working. When I removed leading spaces from all lines in the while-do-done loop, it worked.

Thanks
-GK-
IT is great!
H.Merijn Brand (procura
Honored Contributor
Solution

Re: need help for ftp script

As I said. I hit the nail.
Leading spaces don't show, but they are a killer to here documents.

/me hops around in joy to have seen this, even though the forum kills whitespace

Enjoy, Have FUN! H.Merijn [ Hoping Pete will read this and stresses it on the nag list ]
Enjoy, Have FUN! H.Merijn
GK_5
Regular Advisor

Re: need help for ftp script

I want to put Unix shell commands in the here doc.
How do I do this?

Thanks
IT is great!
H.Merijn Brand (procura
Honored Contributor

Re: need help for ftp script

Show us an example of what you would like to work before we can `fix' your thoughts about this. To be honoust I don't exactly know what you want to achieve.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
GK_5
Regular Advisor

Re: need help for ftp script

On a Unix machine I have a file which has list of files that need to be deleted on Windows server. I can login to Windows server with ftp. I need to delete those files on windows server with single login. At present, it is logging for each file that need be deleted.

Thanks
IT is great!
H.Merijn Brand (procura
Honored Contributor

Re: need help for ftp script

Which is exactly what the script is doing what I posted before:

--8<--- remove.pl
#!/usr/bin/perl

use Net::FTP;
my $f = Net::FTP->new ("10.10.10.10");
$f->login ("user", "password"); # Only _one_ logon
$f->cwd ("dir");

while (<>) {
chomp;
$f->delete ($_);
}

$ftp->quit (); # and _one_ logoff
-->8---

# remove.pl file_with_list_of_files_to_delete

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn