FTP command question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP command question
# 1  
Old 05-21-2009
FTP command question

Hi this is for my knowledge;

I have FTP scripts which looks like this:[i might be wrong Smilie; but dont worry]

HOST=
USER=
PASSwd=

ftp -in .....

bi
mget

exit

--------------
Now my question is : can i use while do loop in this script to pull files from a directory on this FTP server. to my local machine?Smilie

Thanks to all
# 2  
Old 05-21-2009
yes of course you can, put it outside of the ftp code. BUT , this way, you are calling ftp each time it goes through the loop. Depending on what you want to do, you can use mput or mget (if you want to loop through files with a specific extension, for example).

Alternatively, you can also use a language that have better FTP protocol control , such as Python (or Perl) with their FTP modules. eg Python
Code:
#!/usr/bin/env python
import ftplib
server="localhost"
user="anonymous"
password="test@hotmail.com"

try:
    ftp = ftplib.FTP(server)    
    ftp.login(user,password)
except Exception,e:
    print e
else:    
    while <some condition>:
       # do something eg 
       #ftp.dosomething()
.......

# 3  
Old 05-21-2009
Hi ghosdog,

Thanks for your reply. what I understood from your answer or code is ur using python...but I want to use it in reqular ftp...like

HOST=
USER=
PASSwd=

ftp -in .....

bi
cd archive
mget
exit

In my code u see there I am changing into a directory named "archive"...I want to use the while do loop to grab files based on the condition from that directory. I am curious how to do that. I tried but it shows as unknown command.

I know I can use two separate scripts 1) ftp script and 2) while do loop script. But will be great to use one.

Thanks again
# 4  
Old 05-21-2009
Quote:
Originally Posted by henrysmith
Hi ghosdog,

Thanks for your reply. what I understood from your answer or code is ur using python...but I want to use it in reqular ftp...like

HOST=
USER=
PASSwd=

ftp -in .....

bi
cd archive
mget
exit

In my code u see there I am changing into a directory named "archive"...I want to use the while do loop to grab files based on the condition from that directory. I am curious how to do that. I tried but it shows as unknown command.

I know I can use two separate scripts 1) ftp script and 2) while do loop script. But will be great to use one.

Thanks again
do you mean this:
Code:
ftp -in .....

bi
cd archive
mget
while loop here ?? <------------- put while loop here?? if it is, its not correct, as FTP protocol doesn't understand loops....
exit

you have to get the results back from the FTP session and store somewhere, either in variables/array or some file. then do your while loop.
(OR unless your FTP client is sophisticated enough to do such things Smilie )
# 5  
Old 05-21-2009
Thank you so much Ghostdog
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ftp question

I have this FTP script: ADDR=168.218.95.172 ftp -inv $ADDR <<- ftpcmds user HEHCFTP H$h673sp ... (3 Replies)
Discussion started by: lena keung
3 Replies

2. Shell Programming and Scripting

FTP question

HI In my script its like this ------------ echo "Enter filename" read fname ftp -v -n abcd.efh.kk.com << EOF user userid pwd bin mget $fname.tar--not working if i give "$fname", works only as "demo.tar" bye ------------ My target is to get a $fname.tar from a remote host.How... (4 Replies)
Discussion started by: coolkid
4 Replies

3. Shell Programming and Scripting

ftp question

Hi, i have a simple question here-- if we dont use binary while doing a ftp of a file,any sort of problem can arise from this or it is ok. Thanks (2 Replies)
Discussion started by: namishtiwari
2 Replies

4. UNIX for Dummies Questions & Answers

FTP Question

How do you limit an ftp user access to a certain Unix path when putting/getting file to/from your server? And how do you restrict the ftp user from using "cd" or "ls" commands? Given that the ftp user knows the ftp userid, password, and your server ip address. Thanks in advanced :) (1 Reply)
Discussion started by: XZOR
1 Replies

5. UNIX for Dummies Questions & Answers

ftp question???

Hi Look at the below: ftp -i novellftp user $LOGIN pass $PASSWORD bin cd //stecnv16/data/shared/public2/gui/webhelp mget help.zip bye unzip help.zip rm help.zip mv help... (10 Replies)
Discussion started by: gkrishnag
10 Replies

6. Shell Programming and Scripting

FTP Question

How do I setup a parameter driven executable script which FTP's a file (input as a parameter) in Unix (AIX) to my desktop (Windows) ? For example I would ideally like to do this - Unix Prompt> FtpFetch abc.log and get this abc.log on my desktop. Thanks to anyone that can help! I am... (1 Reply)
Discussion started by: kapjag
1 Replies

7. UNIX for Advanced & Expert Users

FTP Question

Once a file is ftped to a server is there a way that you can prevent that file from being overwritten if the same process tries to ftp a file with the same name again? (6 Replies)
Discussion started by: lesstjm
6 Replies

8. UNIX for Dummies Questions & Answers

FTP Question

When a user FTP's to their own directory, they can go up the directory and view others files, of course they can not overwrite them but are able to download them if they wish to, is there any way to stop them from view their files and have them be only able to view files that they have permissions... (3 Replies)
Discussion started by: foresthillian
3 Replies

9. UNIX for Advanced & Expert Users

FTP Question

Hi, I'm attempting to FTP several files using MGET. My problem is that I need to cd to a directory with this naming convention: YYMMDDHHMM - where the hour and minute is unknown When I issue cd /ftpdirectory/YYMMDD* from FTP, I receive "No such file or directory I need a way to get the... (6 Replies)
Discussion started by: kdreaves
6 Replies

10. UNIX for Dummies Questions & Answers

FTP Question

I am really new to unix and want to setup an ftp server on my PC I am running a Ultra 5 with solaris 9 on it. I cannot seem to find *any* documentation on how to do this. So I was hoping somebody could point me in the right direction. :confused: (3 Replies)
Discussion started by: ls=dir
3 Replies
Login or Register to Ask a Question