ftp shell script

Posted on 2004-11-24
Last Modified: 2012-06-27
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.
Question by:wookaka
    LVL 23

    Expert Comment

    You could use HERE i/o redirection:

    Or you could use curl instead of ftp:

    LVL 40

    Expert Comment

    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 for more information.
    LVL 38

    Accepted Solution


    # !/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
    mget file1 file2
    < other script >


    Author Comment

    Wesly had exactly what I needed... any way to have the script echo whats happening back to the screen?
    LVL 40

    Expert Comment

    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.

    Author Comment

    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?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now