Basic bash -- pulling files from an FTP server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Basic bash -- pulling files from an FTP server
# 1  
Old 12-18-2012
Basic bash -- pulling files from an FTP server

Hi guys. Very new to this so apologies if this is ridiculously obvious, but I am not sure why this isn't working. I want to pull a file off an FTP server. I currently do it through windows, which is no problem, but I want to move everything to a Linux box I just installed. wget won't work as the remote directory isn't part of the root directory as defined in the FTP server.

The script is as below. It connects to the ftp, but just sits at the ftp> prompt and goes no further. I do not know why it isn't sending the username and password and completing the script? Can anyone shed any light? I've googled and it seems like it should work...?

Code:
#!/bin/bash
ftp -inv 172.17.1.1
quote user login password
bin
prompt off
cd /opt/SRC
lcd /bin/DST
mget *.*
bye


Last edited by Scott; 12-18-2012 at 01:47 PM.. Reason: Code tags
# 2  
Old 12-18-2012
Please always use code tags when posting any code fragments or data samples. If you are not sure how to use code tags, then please have a look at this forum video tutorial

Try this:-
Code:
ftp -i -n << EOF
open 172.17.1.1
user login password
prompt off
cd /opt/SRC
lcd /bin/DST
mget *.*
EOF

# 3  
Old 12-18-2012
You need to tell it what to do. What you have is a script that will start FTP and then wait until it ends before carrying on and trying to execute the next line, i.e. quote user login password

To get this to be seen as input to the ftp command, you will need to wrap it up a little:-

Code:
#!/bin/bash
ftp -inv 172.17.1.1  <<-EOFTP
quote user login password
bin
prompt off
cd /opt/SRC
lcd /bin/DST
mget *.*
bye 
EOFTP


The EOFTP label at the end marks where the input stops. Mind you, I'm writing this as a ksh writer with very limited bash experience at the moment, so this may not work, but give it a go.

If you indent your code to make it more readable, the EOFTP at the end cannot be space indented or it will be ignored. Use the Tab key instead.



I hope that this helps.

Robin
Liverpool/Blackburn
UK
# 4  
Old 12-18-2012
thanks guys! apologies again, but i'm new to this.

steve.
# 5  
Old 12-18-2012
We were all new to it once too Smilie - and it's nice to have someone display pleasure Smilie rather than the usual blank we probably all get at work. Thanks for that Smilie
Did it do the trick?



Robin
Liverpool/Blackburn
UK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash: Pulling first and last character in string

I am writing a bash script that will find all references to the “Well_List” in the “Comp_File”. I am filtering a Well_List that contains the following: TEST_WELL_01 TEST_WELL_02 TEST_WELL_11 TEST_WELL_22 GOV_WELL_1 GOV_WELL_201 PUB_WELL_57 PUB_WELL_82 . . Comparison... (5 Replies)
Discussion started by: petfyp
5 Replies

2. Solaris

FTP-ing files from Windows server to UNIX server

I need to transfer files from a Windows server to the Unix server and have to run some shell script on it to get the required output. Is it possible to transfer files from Windows server to unix server through any shell script? If so can you please help me with the details. Thanks in... (8 Replies)
Discussion started by: ssk250
8 Replies

3. Shell Programming and Scripting

BASH- Need help pulling data from .emlx

Hello, fellow computer junkies. First time poster! My boss wrote an application (Mavericks 10.9, Mountain Lion 10.8) that checks a user's security settings. The user runs the application, then it spits out an email that is sent back to our inbox showing the results. On our end, we have a mail rule... (5 Replies)
Discussion started by: sudo
5 Replies

4. Solaris

How to FTP (get multiple) unix files to windows using visual basic 6

How to FTP (get multiple) unix files to windows using visual basic 6. I am a list of files in my unix location, need to ftp those files to windows machine using Visual basic 6 or VBA macros. Thanks in Advance (3 Replies)
Discussion started by: sureshmani
3 Replies

5. Shell Programming and Scripting

FTP multiple files from one server to one server

Hi, I'm new to shell script..I have one requriement like - In one server have more than one files,I want to ftp those files to some otehr server.. Ex : test1.pdf test2.pdf Please suggest me how to do (3 Replies)
Discussion started by: venkaswa
3 Replies

6. Shell Programming and Scripting

script for to take files from FTP server to UNIX server and Unzipped that files

script for to take files from FTP server to UNIX server and Unzipped that files (1 Reply)
Discussion started by: sunilamarnadh
1 Replies

7. Shell Programming and Scripting

Bash script pulling variable from query_string

I have a variable embedded in a long string called "commands" coming in on a query_string. I need to copy the string to a file with the variable $loop1 converted before it writes. Right now, it writes the varible itself instead of what it should be. QUERY_STRING... (2 Replies)
Discussion started by: numele
2 Replies

8. Filesystems, Disks and Memory

Not able to FTP the files to a FTP server

Hi , We are facing a weird problem in our project. we need to send some xml & audio files to a remote FTP server from a Linux box, we are doing this in Perl script using Net::FTP->. Issue here is.. when FTPed the files using Perl scripts, only empty files ( 0 byte) are getting created on the... (2 Replies)
Discussion started by: kishorepotta
2 Replies

9. Shell Programming and Scripting

Pulling a list of files from FTP site in a shell script

Hi, I am writting a shell script which will pull a list files (mentioned in one file 1.txt) from external FTP site (for ex: ftp://abcd.efghijk.com/). The 1.txt is in my local unix directory. I have username and password to connect the external FTP site. Also before I pull the files, I need... (0 Replies)
Discussion started by: spatra
0 Replies

10. Shell Programming and Scripting

FTP multiple files from remote server to local server

Hi, I am facing a weired problem in my FTP script. I want to transfer multiple files from remote server to local server everyday, using mget * in my script. I also, want to send an email for successful or failed FTP. My script works for file transfer, but it don't send any mail. There is... (2 Replies)
Discussion started by: berlin_germany
2 Replies
Login or Register to Ask a Question