LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 02-24-2009, 12:47 PM   #1
mikidouglas
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
open ftp.sunfreeware.com
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 sunfreeware.com.
220 ftp.sunfreeware.com 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.
---> PASS XXXX
230-
230-==============================================
230-This is the ftp.sunfreeware.com ftp server
230-
230-If you have not already done so, make sure
230-you have read the Downloading/Installation,
230-FAQ, and Disclaimer links on
230-http://sunfreeware.com.
230-
230-This is a restricted access system. All
230-transfers are logged. If you disagree
230-with this practice, log off now.
230-
230-Questions go to Steve Christensen at
230-the address given on sunfreeware.com.
230-==============================================
230-
230-
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 ftp.sunfreeware.com.
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
zinger919
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 ~~~~~~~~~~~~~~~~~~~~~~
machine ftp.sunfreeware.com
login anonymous
password anonymous
macdef init
cd pub/freeware
dir
bin

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

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

Make .netrc private:
prompt> chmod 600 .netrc

Then just:
prompt> ftp ftp.sunfreeware.com

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
zinger919
LQ Newbie
 
Registered: Aug 2003
Posts: 7

Rep: Reputation: 0
P.S.
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
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196

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

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

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by mikidouglas View Post
>> cat ftp_auth
open ftp.sunfreeware.com
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:

Code:
#!/bin/sh

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


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
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:06 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