How to create an ftp script to transfer files from linux to windows

Hello experts,

I am trying to create a script in order to automate the ftp transfer i do by hand from linux to a windows server. The server belongs to a domain and the user i need to authenticate belongs to an Active Directory (user name: test, password: test for example)
The script i am using is the following. I dunno much about scripting and not so much yet concerning linux so it might be totally wrong.

When i run it, i get the following errors:

'AUTH GSSAPI': command not understood
'AUTH KERBEROS_V4': command not understood
KERBEROS_V4 rejected as an authentication type
User domaintest cannot log in.
Login failed.
Please login with USER and PASS.
Local directory now /u01/app/oracle/scripts/SIDE_DB_Backup/imports
Please login with USER and PASS.
Please login with USER and PASS.
Passive mode refused.  Turning off passive mode.
Please login with USER and PASS.
ftp: bind: Address already in use
Please login with USER and PASS.
Please login with USER and PASS.

Any help for this issue would be more than welcome.

#!/usr/bin/env ksh
 
SERVER=10.250.x.x
LOCALDIR=/u01/app/oracle/scripts/SIDE_DB_Backup/imports
 
# transfer the file
 
ftp -in << EOF
open $SERVER
user domain\test test
binary
lcd $LOCALDIR
cd /Oracle
mput *.dmp
close
EOF

Open in new window

LVL 2
stavramaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

http:// thevpn.guruCommented:
Try this




ftp -inv $FTPS <<END_SCRIPT
quote USER $FTPU
quote PASS $FTPP
cd $FTPD
lcd $BACKUP
mput *
quit
EOF


Of course you have to setup the vars first.

Also check out


http://bash.cyberciti.biz/backup/wizard-ftp-script.php
0
omarfaridCommented:
Step for ftp script

- You should have a script call it myscript that will ftp file to remote server:

cd /localdir
ftp remoteserver <<END
cd /dir
binary
prompt
mput *.dmp
bye
END

- make this script executable:

chmod +x myscript

- For ftp to work without providing any username / password,  use .netrc file in the user's home directory (the one who will run the script). This file should not be readable by others i.e. use
chmod 400 .netrc

The entry in .netrc should be as below:

machine remoteserver
login remoteusername
password mypassword

remoteserver is the server which is the ftp server where you want to sent the file(s)
remoteusername is the remote user login name on the ftp server
mypassword is the password of the remote user on the ftp server

for more info about .netrc, please use man netrc
0
omarfaridCommented:
Hi shakoush2001,

I think you have problems in your script :)
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

http:// thevpn.guruCommented:
Hi Omar
Long time no see how it everything going, the script works fine :) But I need to put in the Vars I think to make it show how it should :)
0
omarfaridCommented:
I think you need to change the END_SCRIPT to EOF or the other way.
 
Also, yo need prompt before the mput command
0
eagerCommented:
There may be timing problems using a shell script to connect with a remote ftp system. It looks like your script (as well as the other suggestions) will send the user id and password before the remote ftp system requests it.

Scripts are not robust and cannot tolerate any changes in remote system behavior, such as server not available or file overwrite questions.  Your script may hang or it may appear to complete without actually doing anything.  

I recommend that you take a look at expect,  (Do 'man expect' for details.)

Expect allows you to program a conversation with a remote system (or program) and make decisions based on the responses received.  You can retry commands, set timeouts, and so forth; essentially anything which you would do yourself can be automated.  With expect you can check to see that the files were correctly transfered and handle problems like server unavailable.
0
omarfaridCommented:
Hi eager,

How you concluded that there is a timing problem at  least to the one I recommended? In my case the ftp client itself will read username and password details from the .netrc file and do the exchange of  username and password properly with the ftp server. This is a tested solution.
0
eagerCommented:
Omar --

Yes, reading userid/password from .netrc will bypass timing problems for that data.

There may be other timing issues.  But the most significant problem is that a bash script cannot respond (or even recognize) when it is out of sync with the remote ftp server.  
0
Bryan ButlerCommented:
I have tackled this 10 years ago and had to use Expect then.   I thought for sure there would come a better way to handle this, but I guess not.  TCL/Expect was the only way to handshake.
0
omarfaridCommented:
I just noted that there is a problem with the script which is the space before EOF. Also please use bye to exit the ftp connection, try

#!/usr/bin/env ksh
 
SERVER=10.250.x.x
LOCALDIR=/u01/app/oracle/scripts/SIDE_DB_Backup/imports
 
# transfer the file
 
ftp -in <<EOF
open $SERVER
user domain\test test
binary
lcd $LOCALDIR
cd /Oracle
mput *.dmp
bye
EOF

You need to be careful as well in not having space before EOF in the last line other wise use <<-EOF

The script I posted earlier is being used for years now and I personally did not face problems with this script and it is also considered safe since you are not including the username and password in the script itself (where in the asker scriot and in using expect, you have to include it part of the script) but kept in a file which is protected and only owner can read.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bryan ButlerCommented:
http://mail.python.org/pipermail/python-list/2000-September/052191.html

This talks about using tcl/expect.  The problem I see with doing it the way omarfarid details is error handling.  If this isn't an issue, then adding a wrapper that does a verification (using "ls" or something) and trying again if it doesn't show up might work for you.  The problem here is the session would have to timeout or you would have to manage the max time to complete, before you could start the next one.  One of the problems with the expect script was different versions of FTP have slightly or significantly different working on responses, so the 'expect' script had to try to handle all of them.  I think they best bet would be using a "module" as suggested in the link above.  I believe there are ftp modules for perl and many other shells too.
0
stavramaAuthor Commented:
Thank you all for your replies. The problem though is, that i still cant login with the user. The user belongs in a domain so whenever i try to login without a script i type on user name :domain\user and i pass the authentication without any problem. If i add this though to the script the authentication fails telling me that User domainuser (without the \) cannot log in.
Is there any way to specify the domain within the script differently, so to pass the authentication process?
0
Bryan ButlerCommented:
Is there a ".hosts" file on the target box that you need to add the sending box hostname to?
0
Bryan ButlerCommented:
Oh, wait, I see, it does work manually, but not in a script.  I believe the "\" is being "interpreted out" as a special character, so you may need to add double or single quotes around that part of the command:

user "domain\test test"
OR
user `domain\test test`
OR maybe escaping the excape:
user domain\\test test
OR even using a backslash:
user domain/test test


0
stavramaAuthor Commented:
Now it is working perfectly. In order to accept the domain user i typed user domain/test test in the script instead of domain\test i was using when i was connecting manually. Quite starnge isn't it?
Thanx a lot for your help.  
0
Bryan ButlerCommented:
Thanks for the question and the points.  Cheers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Server Software

From novice to tech pro — start learning today.