linuxbashftpyad

Check FTP login data using bash


I tried searching for a simple login data check for ftp connection in my bash script. I tried using wput and grep to get the output for a progress bar. Is there a way to check the login data first? I think wput doesn't support this...

Is there anybody who could help me with a good simple solution?

Thanks!


Solution

  • You can use wget to test the connection:

    wget --spider --tries=1 --user=login --password=pass ftp://your-ftp.com/
    if [ $? -ne 0 ]; then
        echo "Failed to connect to ftp host"
    fi
    

    Or you can use ftp command:

    echo 'exit' | ftp ftp://login:pass@your-ftp.com/
    if [ $? -ne 0 ]; then
        echo "Failed to connect to ftp host"
    fi
    

    Note: sending/piping 'exit' command to FTP to force it exit out of interactive mode.