Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 02-24-2009, 12:47 PM   #1
LQ Newbie
Registered: Nov 2006
Posts: 6

Rep: Reputation: 0
FTP automation question..

I dont know if this is the thread to put this question to.. if not please move, i could'nt find a scripting thread!!

Q> i am automating an ftp session like this

a file ftp_auth

>> cat ftp_auth
user anonymous anonymous

and initiating connection

>> ftp -inv < ftp_auth

Now there isnt any problem with connection and all that... but the connection terminates without waiting for prompt.
Here's the output
>> ftp -invd < ftp_auth
Connected to
220 FTP server ready.
---> SYST
530 Please login with USER and PASS.
---> USER anonymous
331 Guest login ok, send your complete e-mail address as password.
230-This is the ftp server
230-If you have not already done so, make sure
230-you have read the Downloading/Installation,
230-FAQ, and Disclaimer links on
230-This is a restricted access system. All
230-transfers are logged. If you disagree
230-with this practice, log off now.
230-Questions go to Steve Christensen at
230-the address given on
230 Guest login ok, access restrictions apply.
---> QUIT
221-You have transferred 0 bytes in 0 files.
221-Total traffic for this session was 803 bytes in 0 transfers.
221-Thank you for using the FTP service on
221 Goodbye.

Now if i do the same thing.. but without using the file ftp_auth, putting in each line manually the ftp connection is not terminated.

Can someone better make me understand where is the QUIT command is coming from ?

.... waiting for reply asap ....
Old 02-24-2009, 01:28 PM   #2
LQ Newbie
Registered: Aug 2003
Posts: 7

Rep: Reputation: 0
.netrc is your friend

Hi mikidouglas, try this:

Create a file in the directory you'll be running the ftp session in named ".netrc". The .netrc file should look something like:

~~~~~~~~~~~~~~~~~~ clip ~~~~~~~~~~~~~~~~~~~~~~
login anonymous
password anonymous
macdef init
cd pub/freeware

~~~~~~~~~~~~~~~~~~ clip ~~~~~~~~~~~~~~~~~~~~~~

The blank line at the end of the macro is mandatory.

Make .netrc private:
prompt> chmod 600 .netrc

Then just:
prompt> ftp

You'll see that all the ftp commands after "macdef init" are executed. Add any you want. Just be sure to have a blank line at the end. You may need certain ftp options (like -p) on some sites.

prompt> man netrc
for more details, but note; contrary to man page, in my experience, the .netrc does NOT have to be in your $HOME directory. This allows you to have many .netrc's in different directories to do different things. Very handy, powerful, & flexible.
Old 02-24-2009, 01:32 PM   #3
LQ Newbie
Registered: Aug 2003
Posts: 7

Rep: Reputation: 0
I think the "QUIT" comes from the EOF (end of file) on your redirected input. Same as doing <ctrl-d>.
Old 02-24-2009, 05:58 PM   #4
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Dunno what exactly your intention is, and if you need to up/download a specific file or that you want to see directory listings etc.

Both wget and ncftpget are able to download from FTP sites in batch, ncftpput can upload files.

I hope this is useful information.

Old 02-25-2009, 08:56 AM   #5
Valery Reznic
ELF Statifier author
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Originally Posted by mikidouglas View Post
>> cat ftp_auth
user anonymous anonymous
You only ask to connect to the ftp site and log in.
If you add some commands (say 'get /some/file')
after 'user anonymous anonymous' ftp will (should) execute them

By the way for the tasks like this I usually use script:


ftp <ip_address> -ivn << FTP_COMMANDS
open ....
user ...
other ftp commands


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
Automation Problems ritam_bkp Linux - Software 10 09-26-2008 10:01 AM
Robot for automation threepwood Linux - Software 1 12-22-2006 10:34 AM
Question on Up2date Automation ekowalc Red Hat 2 11-13-2005 02:59 PM
automation bong.mau Programming 2 09-06-2005 04:26 PM
ftp automation Mad_C Linux - General 12 09-15-2003 09:57 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:48 AM.

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