LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash Script (https://www.linuxquestions.org/questions/programming-9/bash-script-251685/)

zaicheke 11-05-2004 10:26 PM

Bash Script
 
I have two questions related to bash scripting and ftp. First how can i check if a url is valid. Like if ftp://ftp.arandomsite/test exists or if ftp://arandomsite exists but not test. Also how can i get a list of all the files in an ftp directory stored into a variable. Thanks in advance.

randyding 11-05-2004 10:56 PM

Hi,

I highly recommend using ckermit, which can be launched from bash of course.
kermit -C 'take myckermit.scr'
will launch a kermit script myckermit.scr, where you can do commands like
ftp ipaddress
ftp dir
ftp binary
ftp get foo.bin
ftp close

Cedrik 11-06-2004 07:11 AM

I would use curl :

Code:

#!/bin/bash

temp=~/myftp.temp
url=$1

curl $1 > $temp
# if you need a ftp passive connection, do that instead :
# curl --ftp-pasv $1 > $temp

if [ ! $? -eq 0 ]; then
    echo "URL $url is not valid"
    exit 1
fi

# from that point the list of files and directory is in the file ~/myftp.temp
cat $temp

# if you want it on a variable
list=$(cat $temp)

# delete the file for cleanning
rm $temp

save it to, say 'myftp', then chmod +x it and execute it with the url as argument :
./myftp ftp://arandomsite

Bluesuperman 11-07-2004 06:32 PM

Curl is a good suggestion, also look into programs like:

ncftp ncftpbatch ncftpbookmarks ncftpget ncftpls ncftpput ncftpspooler

also lftp is scriptable ... you can place all your FTP commands in a text file and have lftp execute them. I use it for a backup script.

Michael.


All times are GMT -5. The time now is 11:26 PM.