1833847 Members
2218 Online
110063 Solutions
New Discussion

Re: Automate FTP login

 
SOLVED
Go to solution
Stephen Ng
Occasional Advisor

Automate FTP login

I would like to issue one command or write a shell script to excute file transfer using ftp
13 REPLIES 13
suki
Frequent Advisor

Re: Automate FTP login

Hi ,
try the following script.


ftp -i -n -v hostname <
suki
Frequent Advisor

Re: Automate FTP login

Hi ,
try the following script.


ftp -i -n -v hostname <
suki
Frequent Advisor

Re: Automate FTP login

Hi ,
try the following script.


ftp -i -n -v hostname <
Stephen Ng
Occasional Advisor

Re: Automate FTP login

Suki,
If I call this script inside another script, could I pass
the filename as a variable thru the first script.
Tks,
Stephen
suki
Frequent Advisor
Solution

Re: Automate FTP login

Yes. U can. Give as an argument to the file.

Example:

filename: ftpscript.sh
--------------------------------
ftp -i -n -v host1 <
Stephen Ng
Occasional Advisor

Re: Automate FTP login

Suki,
I got error when I ran the script.
I've attached two scripts & the result for
you.
Tks,
Stephen
Yogeeraj_1
Honored Contributor

Re: Automate FTP login

hi,

try this simple one:
#more test.sh
#!/bin/sh
ftp myserver <prompt
cd /home/yd
mput myfile*
bye
EOF


Hope this helps!
Regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Stephen Ng
Occasional Advisor

Re: Automate FTP login

No, it didn't work.
Tks,
Stephen
john korterman
Honored Contributor

Re: Automate FTP login

Hi Stephen,
Try "m.sh" with this content:

#!/usr/bin/sh
ftp -niv $1 <
it would be nice if you always got a second chance
Ron Kinner
Honored Contributor

Re: Automate FTP login

A simpler way than trying to pass variables is simply to have a directory set aside for ftp transfers. Then the first script just copies the file(s) into the directory and calls the second script which ftps everything in the directory (mput *.gz) then the first script deletes the files or moves them to an archive directory. This way there is no limit to the number of files that you can pass.

Ron
Stephen Ng
Occasional Advisor

Re: Automate FTP login

Ron,
That's a good idea. Ijust
have the same thinking.
Tks to all of you.
Stephen
A. Clay Stephenson
Acclaimed Contributor

Re: Automate FTP login

A much better way to do regardless of whether you set up a dedicated transfer directory is to do with Perl using the Net::FTP module.

The big question to ask yourself is "How do I know that my put(s) or get(s) actually worked and that the entire file(s) was transferred intact?" Chances are you don't know and any of these examples don't know either. That's the beauty of Net::FTP; error checking is very simple.

You can download the NET::FTP module from www.perl.com/CPAN
and installation is trivially easy.

To use this in a script, you would do something like this:

ftp.pl file1 file2 file3
STAT=${?}

if [[ ${STAT} -eq 0 ]]
then
echo "All transfers ok"
fi

This will automatically attempt a re-transmit if a file fails.



If it ain't broke, I can fix that.
A. Daniel King_1
Super Advisor

Re: Automate FTP login

ftp has builtin the ability to read a .netrc file (automated ftp). See:

man netrc

for details.
Command-Line Junkie