How to automate the FTP script using shell?

I have problem on automate the FTP using unix shell. Could anyone help?

Regards,
William
will_pohAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
standard ftp clients cannot be automated, at least passwords must be passed interactive
You may try ncftp, which has a .ncftp file.
0
seredaCommented:
LFTP is also neat ftp client.
0
jlevieCommented:
ahoffman's suggestion is a good bet, but he didn't mention the ncftpget/ncftpput utilities that are intended for scripted ftp transfers, check out www.ncftp.com.

You can create shell scripts to transfer files (and entire directory trees) and within the script even detect transfer success, something like:

#!/bin/sh
#
cd incoming
ncftpget -u user -p password ftp.dom . /pub/some-file
if [ $? != 0 ]; then
  echo "Transfer failed"
fi
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

dougisCommented:
you CAN automate ftp with the unix shell, all you need is a .netrc file which will conatin the info for each server you want to connect to.
IE

machine      place.you.connect.to
login      USERIDGoesHere
password      PasswordGoesHere
macdef init
Insert any FTP commands you want to run in here
bye

Then in your crontab place the command ftp -i ServerName at the appropriate time.
Hope that helps
0
dougisCommented:
PS the rights on .netrc MUST be 0600 and it must be owned by the user running the FTP command and exist in their home directory
0
jlevieCommented:
Well of course you can automate a transfer with .netrc. What you can't do is determine the status of a transfer. Typically the exit status will be that of ftp, not the ftp command (get/put). Also most ftp clients don't support recursive gets/puts.
0
ahoffmannCommented:
> you CAN automate ftp with the unix shell ..
NO. NO.
not with standard ftp, just ncftp, or lftp (see sereda's comment)
UNIX ftp is secure, it always ask for password on the tty, never on STDIN or other insecure channels, which can be redirected.
0
dougisCommented:
YES YES it can be automated, that is why the rights to netrc need to be set as I stated in the follow up. (A portion of man ftp follows)
OPTIONS
     The following options may be specified at the command  line,
     or to the command interpreter:

     -d   Enable debugging.

     -g   Disable filename "globbing."

     -i   Turn off interactive  prompting  during  multiple  file
          transfers.

     -n   Do not attempt "auto-login"  upon  initial  connection.
          If  auto-login  is  not disabled, ftp checks the .netrc
          file in the user's home directory for an entry describ-
          ing  an  account  on  the  remote machine.  If no entry
          exists, ftp will prompt  for  the  login  name  of  the
          account on the remote machine (the default is the login
          name on the local machine), and, if necessary,  prompts
          for a password and an account with which to login.

--More--(5%)
This is referring to /usr/ucb/ftp on Solaris (and every other UNIX I have ever used) if the rights are not set correctly on .netrc then the command will fail but if they are set it works like a charm (I use it for a LOT of automated Transfers)
0
ahoffmannCommented:
Yes, No, probably, ...
standard (BSD) ftp cannot. Dot.
Depending on OS and ftp version it might work, or you can use expect to do it.
0
mcriderCommented:
Actually, try this in a script file:

     #!/bin/sh
     ftp -n localhost <<!
     quote user YourUserName
     quote pass YourPassword
     binary
     put file1 file2
     quit
     !


You should not have any problems with passing passwords...


Cheers!



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ahoffmannCommented:
mcrider, nice to learn some more perfect trick here ;-)
0
mcriderCommented:
ahoffmann, so that works on your system?
0
ahoffmannCommented:
yes, on Solaris, FreeBSD and Linux (all BSD-like ftp clients)
Always thought that ftp did it like telnet/login: read from tty directly, but something
seems to be different, 'cause your solution works.
But requires very new ftp clients, which understand the quote command, without it, it does nott work.
0
mcriderCommented:
ahoffmann, the QUOTE command is part of the RFC on ftp.  All ftp clients that conform to the RFC standards will support this method...


Cheers!
0
will_pohAuthor Commented:
Thanks for your answer. It work..
0
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
dhemondCommented:
OMG that is the slickest autoftp script I have seen.  Worked like a champ.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.