LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2004, 11:26 PM   #1
zaicheke
Member
 
Registered: Apr 2004
Distribution: Slackware 10, Open BSD 3.6, Mac OS 10.3.7, Splack 10 beta
Posts: 393

Rep: Reputation: 30
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.

Last edited by zaicheke; 11-05-2004 at 11:27 PM.
 
Old 11-05-2004, 11:56 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
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
 
Old 11-06-2004, 08:11 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
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

Last edited by Cedrik; 11-06-2004 at 08:22 AM.
 
Old 11-07-2004, 07:32 PM   #4
Bluesuperman
Member
 
Registered: Nov 2002
Distribution: Slackware
Posts: 155

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script Linh Programming 4 04-21-2004 06:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM
bash script brian0918 Programming 7 06-12-2003 07:06 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 06:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration