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 02-05-2010, 04:30 PM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Rep: Reputation: 174Reputation: 174
ftp in a bash script question


I am writing a script to do a speed measurement from my ISP's test ftp server. To do this interactively I connect to the server, enter credentials, enable hash and download a test file. The process concludes with something like
Quote:
################################################################
226 Transfer complete.
1048576 bytes received in 2.87 secs (356.6 kB/s)
So I entered the credentials for the server in my .netrc file and created a little bash script as follows
Quote:
#!/bin/bash
cd ~/Desktop
# poiuytrewq is the limit string of the "here" document
ftp 63.162.xxx.xxx <<poiuytrewq
hash
get test.1meg
bye
poiuytrewq
The script executes as expected EXCEPT that I do not see the statistics at the end of the transfer. It terminates thusly
Quote:
#################################################################################################### ############################################
ken@taylor12:~/Desktop$
I have tried adding another ftp command such as ls to the end of the "here" document (in case the results were clipped by the bye command) but to no avail. The ls result immediately follows the ### - no stats I am at a loss. Any suggestions from the community?

TIA,

Ken
 
Old 02-05-2010, 04:35 PM   #2
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Well, to answer my own question....

I added -v (verbose) to the ftp command. I get a bunch of other data which I do not want but I do get the stats I am looking for at the end of the process.

I will leave this thread open to see if someone else has a better idea.

Thanks again,

Ken

Last edited by taylorkh; 02-05-2010 at 04:36 PM. Reason: more info
 
Old 02-05-2010, 05:08 PM   #3
jlinkels
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
wget is a good solution:
Code:
/usr/bin/wget -a /home/jlinkels/wget.log -r -T 60 -t 5 -O /home/jlinkels/reference.pdf http://download.microsoft.com/downlo...a/dotnetfx.exe
You can of course change the -O parameter, use ftp://<filename> to download.

jlinkels
 
Old 02-05-2010, 05:53 PM   #4
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks jlinkels,

I have played with wget in the past - don't remember why. If I am in a real hurry to download something I use Internet Download Manager in an XP virtual machine. It will suck every possible bps from my DSL connection. It will queue many jobs, download all links from a web page, restart downloads etc. I think I looked into wget when I could not get IDM to work under wine. I now have enough horsepower (i7-860 CPU and 8 GB of RAM) to run a virtual machine all the time just in case I need do run a Windows program.

For the purposes of my speed test script - it does what I need. When something seems really slow (as Ubuntu updates were this morning) I can simply fire up the script and get a quick read on my connection throughput.

Regards,

Ken
 
Old 02-05-2010, 06:31 PM   #5
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 594

Rep: Reputation: 141Reputation: 141
The problem might be that a script is running in a non interactive shell
you can try if adding a i to the first line #!/bin/bash -i to force a interactive shell
solves your problem, or add a ! to ftp ! 63.162.xxx.xxx to invoke a interactive shell.

Regards,
Emilio
 
Old 02-05-2010, 06:44 PM   #6
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks Emilio,

I will give this a try and post my results.

Ken
 
Old 02-05-2010, 06:59 PM   #7
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Unfortunately the -i interactive shell did not have any effect. And, the ftp ! did not connect. Thanks anyhow for the suggestions.

Ken
 
  


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 with ftp in a function -- please help! kpj104 Linux - General 1 05-19-2008 10:24 AM
ftp bash script idgeitman Linux - Newbie 1 04-29-2008 04:03 PM
FTP Bash script Elguapo Programming 2 06-07-2007 01:26 PM
bash script AND ftp bokini Linux - General 2 01-04-2006 04:33 PM
how to while in a ftp bash script dezeque Programming 3 06-12-2004 04:13 PM

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

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