FTP Shell script
This post is just to collect comments and feedback on the FTP shell script at:http://willcode4beer.com/tips.jsp?set=bashftp
I notice that the majority of visitors are from Brazil, France, Germany, Italy, Romania, Tawain, and the United Kingdom. So, I am sure the first improvement will be just to translate the page.
I would appreciate hearing about experiences, successes and failures.
Thanks,
Paul
27 Comments:
Its ok. But if you are invoking this shell script from some other programs(like C,java), How will you handle errors.....
Actually, if I were using another language, I'd just ftp within the language instead of using the shell script. Besides error handling, as you mentioned, you get better control of the operation, and the "files" you ftp don't ever have to exist as real files. The can be dynamically created data thats just sent down the wire.
For Java, there is some rudimentary built in support for FTP but, the Jakarta Commons Net library is much better. It would be a much better choice than calling native code. Also, calling the shell from Java could invite some security problems.
There are hundreds of libraries providing FTP support in C/C++ as a quick google will show.
Great, thank you. It work for me.
Why is it that if you put any bash commands after the second EOF, even a simple 'echo "hello"', you get no response? I was trying to use a lock file, as this script is called by another script and I need to determine if it's still running, since it will have variable lengths of time depending on how many files are being transfered.
Hi Sommi6,
It's because EOF stands for "End of File"
Probably the simplest way to do what you want is to create a few functions in the bash script that can be called individually.
Great, it works. But Solaris doesn't know the parameter '-u' :-)
Hi
This is a nice script ..Is it possible to take IP address from a file .So that I can add new server IP as column and the script read server IP from file and execute the script for each server ? Email me on
mohammada@au.specsavers.com
A bit of an aside but can you direct an FTP based on the hostname of the puter? ie the same script can be run from multiple puters so I'd like to put something like..
if $hostname="thiscomputer"
ftp -in theothercomputer
else
if $hostname="theothercomputer"
ftp -in this computer
Does that look like something that should work?
To both anonymous'
Yes, you should be able to read the ip out of a file.
Even easier, just have the file contain something like:
export ip=127.0.0.1
and execute the file from the script. It'll be easier than parsing.
For the hostname, just read it from:
"/etc/hostname"
Should work just fine.
is it possible to retrieve the password from the encrypted file system such as /etc/passwd ?
Having a problem setting a path and filename on Rhel 5.0. I get the error "The system could not find the specified path". It works like a champ if the file is in the same directory as the script. Any suggestions?
Thanks a lot!
nice one, very helpfull.
hi..
Your code is very useful..
Thanks for your efforts.
But unfortunatly didn't worked for me.
and it is asking me password if i execute it.Not sure why this is happening.
please help
didn't work for me "ftp: u: unknown option " message displayed i used F12
ftp -n would work too . Sometimes you get the error
ftp: u: unknown option
OK, I have checked, checked and double checked that I have used the right filename/location but I get the following error when using your script:
"/home/danielgroves/text.txt: No such file or directory"
Any Ideas?
I have tried chmodding it to 777.
works for me, thx!
I am trying to do the same from room directly and it's not working. it's throwing below for the put $filename..
Could not create file.
Thanks *Beer. You're a lifesaver! I'll read up to figure out how it works! Should help when invoking ne other prompt based apps via bash.
i want to take backup of some tables from another pg server using ftp configuration of differennt server in script.sh file , can any one help me ?
thanks ...i wanna learn shell scripting... wnt more help
Thanks!
I had to add the -nv option - but wow this really rocks now.
Can you point me to some code examples about how I can then compress the file (Gzip) and move it to the archive location?
Hi I ve tried to create a ftp shell script to move some files from a specific path in ubuntu /home/rick/ABC/files.txt to a host with a different path. When a debug my ftp connection, I see local y remote folder is the same
Server ftp: 192.168.1.100
user & pass: rick
local path:/ home/rick/NARANJA/files.txt
remote path change according day, month 6 year in a Windows machine
Regards
Hi, I have trouble to create a script. I want to transfers some txt files from an ubuntu machine from a specific folder to windows machine, but when I debug a shell with ftp I see local & remote path are the same path
IP Server ftp: 192.168.1.100
ftp user & pas: rick
onnected to 192.168.1.100.
220-Cerberus FTP Server Personal Edition
220-UNREGISTERED
220-Welcome to Cerberus FTP Server
220 Created by Grant Averett
ftp: setsockopt: Bad file descriptor
---> SYST
500 Not logged in
---> USER rick
331 User rick, password please
---> PASS rick
230 Password Ok, User logged in
---> TYPE I
200 Type Binary
---> CWD ftproot
250 Change directory ok
local: /home/rick/NARANJA/hoy.tar.gz remote: /home/rick/NARANJA/hoy.tar.gz
---> PORT 192,168,1,20,135,107
200 Port command received
---> STOR /home/rick/NARANJA/hoy.tar.gz
500 Invalid Path
---> QUIT
221 Goodbye
*************************************
My script:
#!/bin/bash
clear
filename="/home/rick/NARANJA/hoy.tar.gz"
hostname="192.168.1.100"
username="rick"
password="rick"
cd /home/rick/NARANJA
ftp -ivnd $hostname <<EOF
quote USER $username
quote PASS $password
binary
cd ftproot
put $filename
quit
EOF
how to select local directory
Post a Comment
Subscribe to Post Comments [Atom]
<< Home