Solved

Accounting for \'s

Posted on 2006-06-28
33
424 Views
Last Modified: 2008-10-28
I'm embarassed about asking this question, but 5 hours is long enough.

I have an FTP script that opens a server to "get" data to a web server. We're no long allowed to use .netrc to supply the login/password data...I don't know why.

I log on to the server from the web server to get some files with this logon:
                        server2\\tmccar10

I can do this from the command line--if I add a "\". I've tried up to 5 of the little buggers without success, tried spacing between \'s...getting nowhere.

When I try to put the login/password combo in a ftp script, it doesn't work. I'm sure it had to do with the \'s.  I've tried lining up to 5 of the little buggers without success, tried spacing between \'s...getting nowhere.

I don't know if the \'s will work, or if a variable would be better.

I'd appreciate any help.

Thanks

0
Comment
Question by:tmccar10
  • 8
  • 8
  • 8
  • +3
33 Comments
 
LVL 16

Expert Comment

by:xDamox
ID: 17003304
Hi,

I am not 100% sure what you mean but have you tried:

server2\\\\tmccar10
0
 
LVL 8

Expert Comment

by:Autogard
ID: 17003391
That should work.  Or maybe single quotes:

'server2\\tmccar10'
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17003419
You said that you've tried up to 5 of the 'buggers'?

Realistically, I'd expect xDamox's approach to work, as a \ escapes the following char, making the char get transalted literally,  so:

\\   should become \
and
\\\\  should become \\

Next idea is to try:

"server2\\\\tmccar10"            (including the ")
or
'server2\\\\tmccar10'             (including the ')

You could also try it with 2 slashes -  \\ and the same quotes approach.

(   (()
(`-' _\
 ''  ''

0
 

Author Comment

by:tmccar10
ID: 17003559
I've tried all of these--several more than once.

Four "\" bare, or in "" or in ' ' don't do it.
Two "\" don't either.

I though maybe creating a variable could substitute and kind of get the "\" out of the picture.

0
 
LVL 8

Expert Comment

by:Autogard
ID: 17003606
You say you have an "FTP script" -- what format is this script in?  Is it a bash script or otherwise?  What is the exact command line command that you are trying to use (obviously replacing any sensitive information)?
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17003653
Can you provide the lines in the script where this is allocated? WE'll then get a better idea of what we are trying  to work with?

(   (()
(`-' _\
 ''  ''
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17003662
Autogard - Great minds think alike?!
0
 
LVL 8

Expert Comment

by:Autogard
ID: 17003698
Haha, yup!  :)  They should start showing the seconds as well as the hour and minute -- just for fun.  :)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17003924
this is a linux TA, hence the question: where do you use the backslaches? somewhere in username or password, or in the path?
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17003980
>Haha, yup!  :)  They should start showing the seconds as well as the hour and minute -- just for fun.  :)

I'll flag that one up in the community support area - Could become proof of the existence of telepathy:

http://www.experts-exchange.com/Community_Support/Q_21902508.html
0
 
LVL 8

Expert Comment

by:Autogard
ID: 17003989
Good one!
0
 

Author Comment

by:tmccar10
ID: 17005504
Sorry to take so long to get back

The slashes are part of the password.

Thanks
################################

 Code:
#!/bin/sh

#"server2\\\\tmccar10"=$slog
ftp -i  <<**
epsv4  
open xx.x.xx.xx
USER server2\\\\tmccar10
PASS psword
#
cd //vol/npd/npdgpweb
lcd //proj/psl/www/namer/pslplan/partadv/pdfs
binary
mget  *.pdf *.txt
bye
**
0
 
LVL 8

Expert Comment

by:Autogard
ID: 17005538
Replace each of the two backslashes with %5C and see if that helps.
0
 
LVL 8

Expert Comment

by:Autogard
ID: 17005580
http://www.demon.net/helpdesk/producthelp/ftp/ftp/batchftp.html -- "Strange characters in filenames or passwords can be included by using the URL character encoding system....."
0
 
LVL 27

Expert Comment

by:Nopius
ID: 17005845
tmccar10: try this:
USER server2\tmccar10
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17007119
> The slashes are part of the password.
slashes are no problem, my question was about backslashes (as you used in your question).

> USER server2\\\\tmccar10
this is a username and evaluates to the string literal server2\\tmccar10 in the unix world
means that this litera willbe send as username with ncftp (or whatever insecure ftp you have which can read username and password from a stream).

This username sounds like a NT-domain username. Are you sure you need to give the domain part?
If the remote system is a unix-like system, I guess that the username is simply  tmccar10
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 27

Expert Comment

by:Nopius
ID: 17007182
ahoffman,

> > USER server2\\\\tmccar10
> this is a username and evaluates to the string literal server2\\tmccar10 in the unix world

yes, that's correct, but as I suggest NT domain full username should look like 'server2\tmccar10', not \server2\\tmccar10' and not 'tmccar10'


BOTH syntaxes of USER will expand to server2\tmccar10:

USER server2\\tmccar10
and
USER server2\tmccar10

so we don't need to escape '\' there, but if we do, it expands to the same string :-)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17007336
USER server2\tmccar10  used in a shell (as posted above) expands to  USER server2tmccar10
(except someone has a special patched /bin/sh :-)
0
 
LVL 27

Expert Comment

by:Nopius
ID: 17007447
ahoffman:

root@sf250 # cat <<EOF
root@sf250 > a\b
root@sf250 > a\\b
root@sf250 > EOF
a\b
a\b
0
 
LVL 27

Expert Comment

by:Nopius
ID: 17007457
and from 'man sh', search for '<<':

2.  (escaped) \newlines are removed; and
3.  \ must be used to quote the  characters \, $, and `.

so my man pages are also patched :-)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17007633
dooh, shame on me, you're right, here documents seem to be special. Patched myself:)
0
 

Author Comment

by:tmccar10
ID: 17007952
Wow-

You folks are dealing with a rank amateur (if you couldn't tell). I'm capable of some basic stuff, but I've spent much of my time getting pieces of info to help me get through.

I don't know if the server I'm trying to get the files from is NT or UNIX-type. I'll find out. What do I do if it IS NT?

Our web server has just been changed from a UNIX box to one using LINUX, hence the other changes.

If it makes any difference, the .netrc file I used before had server2\\tmccar10 as the logon ID and it work fine.

Thanks for all the interest and activity. I'm learning as I read.
0
 

Author Comment

by:tmccar10
ID: 17008728
The server I'm opening IS an NT server, but again, the .netrc and ftp programs like WSFTP required server2\\tmccar10.

Thanks
0
 
LVL 27

Expert Comment

by:Nopius
ID: 17014485
tmccar10

Please run from command line (from shell):

sh$ ftp -idt  <<EOF
open xx.x.xx.xx
USER server2\\tmccar10
PASS psword
cd /vol/npd/npdgpweb
lcd /proj/psl/www/namer/pslplan/partadv/pdfs
binary
mget  *.pdf *.txt
bye
EOF

and tell us what it says, of cause change x.x.x.x and psword to the valid values.

1) Using ** in shell script for input termination is dangerous. So I used EOF instead
2) I don't see any reason of why do you use 'epsv4' at the very first line

0
 
LVL 8

Expert Comment

by:Autogard
ID: 17015000
tmccar,

Did you try my suggestion above:

"Replace each of the two backslashes with %5C and see if that helps."

Just curious.
0
 

Author Comment

by:tmccar10
ID: 17016879
Thanks-

Autogard-- changing \\ with %5C didn't seem to help.

Nopius--It's interesting to look at the fifth line below: USER USER? Look like it could be a problem.

I got the same return messages about USER USER. Below are pieces of Nopius' code and mine. Both seem to hang up on USER

SNIPPET from  Nopius' code
************************************
tmccar10@xxxx531:~ $  ftp -idt  <<EOF
> open xx.x.xx.xx
> USER server2\\\tmccar10
> PASS pword
> EOF
--------------------------------------
Connected to xxxxxxxxxx.xxx.xxx.com.
220 netapp ftp server
ftp_login: user `<null>' pass `<null>' host `xx.x.xx.xx'
Name (xx.x.xx.x:tmccar10): ---> USER USER server2\\tmccar10
500 'USER USER server2\\tmccar10': Command not understood.
ftp: Login failed.
?Invalid command.
---> QUIT
221 Goodbye.


*******************************************************
SNIPPET from MY code
#
USER fordna2\\tmccar10
PASS ellen66
#
-----------
Name (19.5.90.99:tmccar10): 'USER   ': Command not understood.
ftp: Login failed.
Please login with USER and PASS.
Local directory now /proj/psl/www/namer/pslplan/partadv/pdfs
Please login with USER and PASS.
Please login with USER and PASS.
************************************
0
 
LVL 8

Expert Comment

by:Autogard
ID: 17017446
tmccar, I meant change each backslash with %5C, so:

server2%5C%5Ctmccar10
0
 

Author Comment

by:tmccar10
ID: 17017641
Thanks

That's the way I tried it--server2%5C%5Ctmccar10.

0
 
LVL 27

Expert Comment

by:Nopius
ID: 17022820
tmccar10:
let's modify script a little  server ip now given in command line, USER and PASS keywords are stripped, everything else as it was
sh$ ftp -idt  x.x.x.x <<EOF
server2\\tmccar10
psword
...

EOF
0
 

Author Comment

by:tmccar10
ID: 17029964
Thanks Nopius-

Tried several configurations with/without PASS USER.

This seems to be going fro bad to worse.

Here's what I got with neither "prompt":

Connected to pdc00024.pd3.ford.com.
220 netapp ftp server
ftp_login: user `<null>' pass `<null>' host `19.5.90.99'
Name (19.5.90.99:tmccar10): ---> USER tmccar10
331 Password required for tmccar10.
Password:
---> PASS XXXX
530 Login incorrect.
ftp: Login failed.
?Invalid command.
?Invalid command.
?Invalid command.
?Invalid command.
---> CWD //vol/npd/npdgpweb
530 Please login with USER and PASS.
Local directory now /proj/psl/www/namer/pslplan/partadv/pdfs
---> TYPE I
200 Type set to I.
---> TYPE A
ftp: setsockopt (ignored): Permission denied
---> EPSV
'EPSV': Command not understood.
disabling epsv4 for this connection
---> PASV
---> NLST *.pdf
Please login with USER and PASS.
ftp: setsockopt (ignored): Permission denied
---> PASV
---> NLST *.txt
Please login with USER and PASS.
---> QUIT
221 Goodbye.
0
 
LVL 27

Expert Comment

by:Nopius
ID: 17034977
tmccar10, really you are very close to solution, things go better and better :-)

I noticed 'user' and other commands are case sensitive in Linux...
I tested following command, and it works for me:

/usr/bin/ftp -idn x.x.x.x <<EOF
user server2\\tmccar10 psword
cd /vol/npd/npdgpweb
lcd /proj/psl/www/namer/pslplan/partadv/pdfs
binary
mget  *.pdf *.txt
bye
EOF

0
 

Author Comment

by:tmccar10
ID: 17043089
Thanks Nopius-

First time I tried that combo of lower cases AND skipping the PASS "prompt"

It's strange, I still get the prompt for password, but if I hit another ENTER it process as it should.

It DOESN'T work (probably for that reason) in the CRON that calls it up.

Any ideas before I close this up?

Thanks again.
0
 
LVL 27

Accepted Solution

by:
Nopius earned 50 total points
ID: 17046986
Probably you missed some of flags of the command '-idn' is working (I tested on Linux and Solaris FTP client).
Try to use this command exactly as I posted (with full path to ftp client, hostname/ip in command line, with the same flags and with password right after username).

You may get password prompt when using 'user' command with username only. But it can be used with username and password in one line.
Yes, from cron it may not work because of interactive prompts.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now