473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using FTP in a unix shell script

1 New Member
I am using following shell script to ftp files to another server
but this is failing as the shell script changes the user name for the ftp login
the correct user name is 'ag\invprint' which the script is fetching from a file using grep command but the ftp log says the script is trying to logon as user 'aginvprint'

Looks like the script is removing the character '\' when trying to ftp

Can someone please help and let me know how to fix this issue ?

Script is as follows .............
-------------------------------------------------------------------------------------------------------------------
cd /home/DWETL
server=`grep "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $2}'`
FTP_USERID=`gre p "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $3}'`
PASSWD=`grep "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $4}'`
PS_DESTDIR=`gre p "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $5}'`
dest_path="cd $PS_DESTDIR"
echo "User name .. " $FTP_USERID > ~/AG_Priory_Park. log
echo "Password .. " $PASSWD > ~/AG_Priory_Park. log
`ftp -i -n -v $server <<... >~/AG_Priory_Park. ftp
user $FTP_USERID $PASSWD
ascii
$dest_path
put copy.sch
quit
...`

-------------------------------------------------------------------------------------------------------------------

Output of AG_Priory_Park. ftp is as follows
-------------------------------------------------------------------

Connected to 10.160.200.22.
220 Microsoft FTP Service
331 Password required for 'aginvprint'.
530 User 'aginvprint' cannot log in.
Login failed.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
200 PORT command successful.
530 Please login with USER and PASS.
221


Cheers
Nitin
Aug 4 '07 #1
9 14207
coaxfiber
60 New Member
I am using following shell script to ftp files to another server
but this is failing as the shell script changes the user name for the ftp login
the correct user name is 'ag\invprint' which the script is fetching from a file using grep command but the ftp log says the script is trying to logon as user 'aginvprint'

Looks like the script is removing the character '\' when trying to ftp

Can someone please help and let me know how to fix this issue ?

Script is as follows .............
-------------------------------------------------------------------------------------------------------------------
cd /home/DWETL
server=`grep "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $2}'`
FTP_USERID=`gre p "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $3}'`
PASSWD=`grep "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $4}'`
PS_DESTDIR=`gre p "AG_PS" $XXTNG_TOP/etc/ftp.dat | awk '{print $5}'`
dest_path="cd $PS_DESTDIR"
echo "User name .. " $FTP_USERID > ~/AG_Priory_Park. log
echo "Password .. " $PASSWD > ~/AG_Priory_Park. log
`ftp -i -n -v $server <<... >~/AG_Priory_Park. ftp
user $FTP_USERID $PASSWD
ascii
$dest_path
put copy.sch
quit
...`

-------------------------------------------------------------------------------------------------------------------

Output of AG_Priory_Park. ftp is as follows
-------------------------------------------------------------------

Connected to 10.160.200.22.
220 Microsoft FTP Service
331 Password required for 'aginvprint'.
530 User 'aginvprint' cannot log in.
Login failed.
530 Please login with USER and PASS.
530 Please login with USER and PASS.
200 PORT command successful.
530 Please login with USER and PASS.
221


Cheers
Nitin

hi,


Can I ask you something? I'm not yet familiar to your script. But would you tell me how to do some basics of FTP.

how could i command a "ls -al" to another server and get that log to my current server.

my user name is: coax
my password is: jazz
command: ls -al


- I want to do this continuously w/o being ask with my password. Of course I could enter my password "jazz" with my script instead of manually entering FTP
and then ask for my password.
- I've already asked this question before but they advised me to use 'SSH with no password' by didn't succeeded to that method because our administrator doesn't allow that one.

Thank You Very Much
-coaxfiber
Aug 6 '07 #2
prn
254 Recognized Expert Contributor
It looks like you're trying to ftp to a windows box using active directory authentication. It also looks like you're extracting the destination information from a file in /etc (odd in itself).

The traditional (more than traditional, actually specified in the standards) is that autologin data goes not in /etc/ftp.dat, but in $HOME/.netrc. Check the ftp and netrc man pages for information.

Another (good) possibility is to use ncftp instead of the standard ftp. The open source ncftpput and ncftpget were developed specifically to make ftp scripting work well. Check out http://www.ncftp.com/ for documentation and downloads.

I have used both .netrc and ncftp with success. Much may depend on what all you want to do and what kinds of restrictions you may face.

As far as backslashes go, you will need a pair of them in order to hand one off to the process. In general, a backslash means "take the next character literally" to the unix shell. In your case, the "next character" is "i". You want it to be a backslash, so you need to use a backslash to tell the shell that you actually want a backslash there.

HTH,
Paul
Aug 6 '07 #3
prn
254 Recognized Expert Contributor
- I've already asked this question before but they advised me to use 'SSH with no password' by didn't succeeded to that method because our administrator doesn't allow that one.
Another alternative is to use RSA authentication instead of a password. Look up the SSH docs and set up your account to accept your RSA key (which you keep on the box you're trying to connect from. See, e.g., http://sial.org/howto/openssh/publickey-auth/ for how to do it.

RSA authentication is enabled by default in a typical SSH installation. You are evidently not the sysadmin on the box you are connecting to, but it seems unlikely that your system admin would object to RSA public key authentication in principle. (Of course, s/he may have a problem with whatever it is you are intending to do, but that is a different matter and I can't comment on that.)

Paul
Aug 6 '07 #4
coaxfiber
60 New Member
Another alternative is to use RSA authentication instead of a password. Look up the SSH docs and set up your account to accept your RSA key (which you keep on the box you're trying to connect from. See, e.g., http://sial.org/howto/openssh/publickey-auth/ for how to do it.

RSA authentication is enabled by default in a typical SSH installation. You are evidently not the sysadmin on the box you are connecting to, but it seems unlikely that your system admin would object to RSA public key authentication in principle. (Of course, s/he may have a problem with whatever it is you are intending to do, but that is a different matter and I can't comment on that.)

Paul
Hi,

I'm currently login in unix not in Windows.
I tried to use RSA/DSA , I followed the procedures on how to do it, but still not working.

I have read some articles on the net and found this useful.:



#!/bin/sh
HOST='ftp.users .qwest.net'
USER='yourid'
PASSWD='yourpw'


ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
ls -al > FILE
get FILE
quit
END_SCRIPT
exit 0

this works good. but my problem now is that limited command runs on ftp. not all unix command works on ftp. FYI.

So I'm still thinking that I can to this using TELNET.

quote USER $USER
quote PASS $PASSWD

--->something like this.

Thanks Very Much.
Aug 7 '07 #5
coaxfiber
60 New Member
Another alternative is to use RSA authentication instead of a password. Look up the SSH docs and set up your account to accept your RSA key (which you keep on the box you're trying to connect from. See, e.g., http://sial.org/howto/openssh/publickey-auth/ for how to do it.

RSA authentication is enabled by default in a typical SSH installation. You are evidently not the sysadmin on the box you are connecting to, but it seems unlikely that your system admin would object to RSA public key authentication in principle. (Of course, s/he may have a problem with whatever it is you are intending to do, but that is a different matter and I can't comment on that.)

Paul
Hi, this is what i got..
------------------------------------------------------------
Host key not found from database.
Key fingerprint:
ximen-cohel-ganup-zacet-soseh-sycab-hekig-huzud-raron-hovet-raxox
You can get a public key's fingerprint by running
% ssh-keygen -F publickey.pub
on the keyfile.
Host key saved to /home/coax/.ssh2/hostkeys/key_22_10.120.1 38.11.pub
host key for 10.120.138.11, accepted by coax Wed Aug 08 2007 02:10:39 +0800

------------------------------------------------------------

i dunno why is it .ssh2 ? what's the difference between .ssh and .ssh2?

Tnx..
Aug 7 '07 #6
prn
254 Recognized Expert Contributor
I'm currently login in unix not in Windows.
The link I posted http://sial.org/howto/openssh/publickey-auth/ is really much more oriented to unix/linux than windows, so that should be fine

I tried to use RSA/DSA , I followed the procedures on how to do it, but still not working.
I have tested those procedures myself and they worked fine for me. We'll need more details.

this works good. but my problem now is that limited command runs on ftp. not all unix command works on ftp. FYI.
That's right. ftp is NOT INTENDED to be a login shell. It's intended for file transfer, not for general use.

So I'm still thinking that I can to this using TELNET.
Personally, I always discourage using TELNET for almost anything. SSH is much better. Security is important and telnet's security is lousy. SSH is far preferable. One of the first things I always do when I set up a unix or linux box is to disable telnet and ftp. (Use sftp or scp instead.)

From your next post:
Hi, this is what i got..
What you got *how*?

You can get a public key's fingerprint by running
% ssh-keygen -F publickey.pub
on the keyfile.
That's not right at all. Check the man page for ssh-keygen. The -F switch is to
Search for the specified hostname in a known_hosts file, listing any occurrences found. This option is useful to find hashed host names or addresses and may also be used in conjunction with the -H option to print found keys in a hashed format.
The -l (lowercase L) switch is for showing a fingerprint. For example:
Expand|Select|Wrap|Line Numbers
  1. $ ssh-keygen -l
  2. Enter file in which the key is (/home/prn/.ssh/id_rsa):
  3. 2048 76:2a:13:20:98:36:5f:5f:ea:9a:46:36:13:22:af:b4 /home/prn/.ssh/id_rsa.pub
i dunno why is it .ssh2 ? what's the difference between .ssh and .ssh2?
Interesting question, but even more relevant is the question of what you did to generate this output.

I'd suggest wiping out everything in .ssh2 and probably most of what's in the .ssh directory of both your login machine and the one you want to connect to. Then start over following the directions for how to generate the keys. Note that the reference page says "Do not use your account password, nor an empty passphrase", but if I understand correctly that you want to run the script when you are not logged in, you would not be able to use the ssh-agent solution and you would need to generate the key with no passphrase, i.e., an empty passphrase, so just hit enter. Otherwise, follow the instructions right through the part about "key distribution". You should then be able to ssh from your account on the "current" computer to your account on the "other" server without being asked for a password.

Once you can do that, you can run any command or script you want on the "other" server. In particular, you can run commands that are not part of the limited repertoire of FTP.

Of course, what you actually said you were going to do was run "ls -al" "continuous ly". I hope you mean that you are going to run it "at intervals" rather than all the time. I presume this means you are polling for some condition on the remote machine and then you plan to do something with the result, but what you plan to do with the result is completely unclear and I do have to wonder if I am just giving you the ammunition to shoot yourself in the foot. Please do try not to run anything "continuous ly". Your sysadmin will not thank me for enabling you if you do. Please be considerate of your sysadmin and of other users and not tie up resources on the remote host unnecessarily. If you have to poll the other machine, do it at reasonable intervals and then do whatever you must.

Also, instead of running a script on your local machine that polls the other machine, perhaps it would be a better idea to run a script on the remote machine that polls for the relevant condition and then either does what must be done or notifies your local machine. Have you thought of that? You can set up a cron job on the remote host and then have it do what must be done there.

If both your "local" and "remote" hosts need to be involved, then perhaps the remote host should poll for the file and then scp it to your local box. There are always many ways to organize such tasks. The more I think about what little you have told us so far, the less confident I am that I understand what you are doing.

Paul
Aug 8 '07 #7
coaxfiber
60 New Member
The link I posted http://sial.org/howto/openssh/publickey-auth/ is really much more oriented to unix/linux than windows, so that should be fine


I have tested those procedures myself and they worked fine for me. We'll need more details.


That's right. ftp is NOT INTENDED to be a login shell. It's intended for file transfer, not for general use.


Personally, I always discourage using TELNET for almost anything. SSH is much better. Security is important and telnet's security is lousy. SSH is far preferable. One of the first things I always do when I set up a unix or linux box is to disable telnet and ftp. (Use sftp or scp instead.)

From your next post:

What you got *how*?


That's not right at all. Check the man page for ssh-keygen. The -F switch is to


The -l (lowercase L) switch is for showing a fingerprint. For example:
Expand|Select|Wrap|Line Numbers
  1. $ ssh-keygen -l
  2. Enter file in which the key is (/home/prn/.ssh/id_rsa):
  3. 2048 76:2a:13:20:98:36:5f:5f:ea:9a:46:36:13:22:af:b4 /home/prn/.ssh/id_rsa.pub

Interesting question, but even more relevant is the question of what you did to generate this output.

I'd suggest wiping out everything in .ssh2 and probably most of what's in the .ssh directory of both your login machine and the one you want to connect to. Then start over following the directions for how to generate the keys. Note that the reference page says "Do not use your account password, nor an empty passphrase", but if I understand correctly that you want to run the script when you are not logged in, you would not be able to use the ssh-agent solution and you would need to generate the key with no passphrase, i.e., an empty passphrase, so just hit enter. Otherwise, follow the instructions right through the part about "key distribution". You should then be able to ssh from your account on the "current" computer to your account on the "other" server without being asked for a password.

Once you can do that, you can run any command or script you want on the "other" server. In particular, you can run commands that are not part of the limited repertoire of FTP.

Of course, what you actually said you were going to do was run "ls -al" "continuous ly". I hope you mean that you are going to run it "at intervals" rather than all the time. I presume this means you are polling for some condition on the remote machine and then you plan to do something with the result, but what you plan to do with the result is completely unclear and I do have to wonder if I am just giving you the ammunition to shoot yourself in the foot. Please do try not to run anything "continuous ly". Your sysadmin will not thank me for enabling you if you do. Please be considerate of your sysadmin and of other users and not tie up resources on the remote host unnecessarily. If you have to poll the other machine, do it at reasonable intervals and then do whatever you must.

Also, instead of running a script on your local machine that polls the other machine, perhaps it would be a better idea to run a script on the remote machine that polls for the relevant condition and then either does what must be done or notifies your local machine. Have you thought of that? You can set up a cron job on the remote host and then have it do what must be done there.

If both your "local" and "remote" hosts need to be involved, then perhaps the remote host should poll for the file and then scp it to your local box. There are always many ways to organize such tasks. The more I think about what little you have told us so far, the less confident I am that I understand what you are doing.

Paul
Hi,

I'm not in the office right now. But remembering what i was doing in my terminal last night and following the instructions given from the page you had posted. I think I removed the option "-f" because it gives an error message.

I just need to access the other servers just to interrogate some elements to have information and fetch in to my current server. Not exactly the 'ls -al' command.
Aug 8 '07 #8
prn
254 Recognized Expert Contributor
Hi coax,

I'm not in the office right now. But remembering what i was doing in my terminal last night and following the instructions given from the page you had posted. I think I removed the option "-f" because it gives an error message.
Be careful to note that "-f" is NOT the same as "-F" As switches to ssh-keygen, -F searches for a hostname and -f specifies a filename (when used WITH -l or various other switches).

I just need to access the other servers just to interrogate some elements to have information and fetch in to my current server. Not exactly the 'ls -al' command.
OK. That's good. It sounds even more to me like you ought to run a script on the remote and have it send something to your local host if and when if finds the trigger conditions.

And BTW, here's an even better reference for how to set up SSH to do that sort of thing unattended: http://www.ibm.com/developerworks/library/l-keyc.html

Using the "keychain" utility that part 2 of this article series describes, you should be able to run an unattended cron job that is much more secure than with an empty passphrase. The keychain page in the links says that "Current versions of keychain are known to run on Linux, BSD, Cygwin, Tru64 UNIX, HP-UX, Mac OS X, and Solaris". I don't know what variety of Unix/Linux you are using, but this seems fairly promising.

HTH,
Paul
Aug 8 '07 #9
eileen365
1 New Member
Another alternative is to use RSA authentication instead of a password. Look up the SSH docs and set up your account to accept your RSA key (which you keep on the box you're trying to connect from. See, e.g., http://sial.org/howto/openssh/publickey-auth/ for how to do it.

RSA authentication is enabled by default in a typical SSH installation. You are evidently not the sysadmin on the box you are connecting to, but it seems unlikely that your system admin would object to RSA public key authentication in principle. (Of course, s/he may have a problem with whatever it is you are intending to do, but that is a different matter and I can't comment on that.)

Paul
This is exactly the problem I'm having! I'm ftp'ing from an hp Tru64 machine to a windows machine and normally I don't have a problem. With this particular windows machine I have to use domain name\login id and the '\' is throwing me off. I'm building a .netrc file and I've tried double \, single quotes aroung the \...seems like I've tried everything. Here is a portion of my script. First I define the variables, then I build the .netrc:

USERID="domain\ loginid"
PASSWORD="xxxxx x"
and I build the .netrc below:

# Create a .netrc
echo "machine $MACHINE" >> ~/.netrc
echo "login $USERID" >> ~/.netrc
echo "password $PASSWORD" >> ~/.netrc
echo "macdef init" >> ~/.netrc
echo "prompt off" >> ~/.netrc
echo "bin" >> ~/.netrc
echo "lcd $WRKDIR" >> ~/.netrc
echo "cd $TGTDIR" >> ~/.netrc
echo "mput *.*" >> ~/.netrc
echo "quit" >> ~/.netrc
echo "" >> ~/.netrc

# Change the permissions of the .netrc
/sbin/chmod 600 ~/.netrc

When I run as is, the script tries to login as
domainloginid.

If I put quotes around the \ I get:
domain" " loginid

If I try single quotes I get a mismatched quote error.

If i use \\, both get ignored and the script tries to login as
domainloginid

I've used \ in front of special characters when specifying the password but I didn't expect this kind of problem. Is there a combination I'm missing.
Aug 20 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3008
by: gmuldoon | last post by:
Help please. Setup: RH EL3, PHP 4.3.5, Apache 1.3.29 running as user "nobody". Have a bash script named shell_script. Telnet to server as user "nobody" ("nobody" having been given /bin/bash as temp shell), can run this script from command line, no problems. Created a php script including the line:
2
5667
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info into a file with a 'ps' command. My question is "How to explicitly specify a Korn shell to be used by perl?" Eg of my perl code: ## Begin code snippet..
1
2062
by: dk | last post by:
is there any way to invoke a unix shell script from .net? tia, dk
2
4545
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the the function due to its
6
2606
by: kabrit | last post by:
Entrez "aide" pour afficher à nouveau les noms de produits. Entrez "quitter" pour quitter. *********************************************************** DB2.PE IBM_db2msen81... Preparing... ################################################## IBM_db2msen81
7
3547
by: kamkwokho | last post by:
Could any answer following questions as many as you can. ii) Write a C shell script convertmin which will read in a number, thought of as representing minutes, and print out the number of hours/minutes it represents so: $ convertmin Enter a number of minutes: 128
0
3057
by: Aashif | last post by:
I want to call Unix Shell script which is available in other Server (Unix server) from windows application using C#. Currently the shell script runs the C program but the GUI is not good, So I want to create GUI in C# windows application and call that C program using Shell script so first I have to call unix shell script from C#. Please guide me friends.
9
78371
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell script and export the result to a file. Any code snippet on this will be helpful.
16
9155
by: pereges | last post by:
Do you see anything wrong about this method ? For eg. I write a shell script a.sh containing : cc -o test file1.c file2.c file3.c and then execute the shell script ( sh a.sh) to compile and create the executable. What is the difference between this method and writing a make file ?
0
8968
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.