[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3500
  • Last Modified:

ftp shell script

I need a shell script to connect to an FTP server, enter a UN/PW download 2 files, dissconnect from the server and then continue running other scripts.
I've created a script but it goes into the ftp command line and stops executing until I manually exit out of ftp.
0
wookaka
Asked:
wookaka
1 Solution
 
brettmjohnsonCommented:
You could use HERE i/o redirection:
http://www.dbforums.com/t1061280.html

Or you could use curl instead of ftp:
http://curl.haxx.se/mail/archive-2004-02/0086.html


0
 
jlevieCommented:
The easiest solution to this would be to use the ncpftpget tool from the ncftp package. It is furnished with many Linux distro's, although it might be installed by default. See http://www.ncftp.com/ncftp/ for more information.
0
 
wesly_chenCommented:
Hi,

-----
# !/bin/sh

/usr/bin/ftp -n  (ftp server or IP) <<ii
user login-name password
cd (path to the files)
lcd /home/dir-to-put-file  <== place you want to put locally
binary
mget file1 file2
quit
ii
< other script >
------

Wesly
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
wookakaAuthor Commented:
Wesly had exactly what I needed... any way to have the script echo whats happening back to the screen?
0
 
jlevieCommented:
The drawback of using Wesly's technique is that you can't tell if the transfer actually worked. The exit status of ftp will be 0 whether you actually login successfully or transfer files. Using ncftpget you'll have an exit status of 0 only if the login and transfer actually works.
0
 
wookakaAuthor Commented:
Thanks for the information but at this point I'm not too worried about error checking since the script will always be run manually. I would be intrested to see the output of the script as it runs the commands though. Anyone know how to do this if possible?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now