Doubt in .netrc file for ftp login


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Doubt in .netrc file for ftp login
# 8  
Old 10-21-2013
On my machine it used to work with:
* ftp
* lftp
* sftp

And it is supposed to work with wgetand curlas well.
# 9  
Old 10-21-2013
When the ftp command uses .netrc to look up credentials for a remote server, it looks for the file .netrc in the home directory of the user under which the ftp command is running. Therefore, every user (including root) will each have their own .netrc file. Ftp looks up the 'machine' name and uses the credentials it finds to make the connection to the remote ftp server.

Unless you have one user with multiple accounts on the remote server there is no conflict. If you do have that then I must ask why?

Does that help or have I misunderstood your question?
# 10  
Old 10-22-2013
Quote:
Originally Posted by sea
Uh Smilie
I used to use .netrc for like 3 ftp servers at the 'same time'.
Meaning i acutaly had 4 entries for 3 servers, 1 been quoted out.
Maybe it was just an illusion that the files got uploaded and were to be seen on the website.

The only error i experienced with .netrc were when i deleted the password 'collum' of a line.

Syntax from manpage: sftp
Code:
sftp [user@]host[:dir[/]]

Just curious, why make a file (~/.netrc) that contains all required info on 1 line, if it can handle only 1 entry?
I thought it was ment like: you pass the host to [s]ftp, which will open ~/.netrc and read the line containing host, obviously, it 'should' check for any user parameter to be on the same line too, if there are multiple identical hosts.

Well, on Fedora it seems to work that way.
Code:
# man netrc
DESCRIPTION
     This file contains configuration and autologin information for the File Transfer Protocol client ftp(1).
........................

So .netrc only used by the ftp protocol not sftp.
sftp works over the ssh protocol.

lftp uses the ftp and because of it uses the .netrc
from lftp trace
Code:
open("/root/.netrc", O_RDONLY)

curl and wget have ftp capabilities.
Code:
wget "options/parameters" ftp://10.100.110.83 .....other options

curl needs the -n parameter for .netrc
Code:
curl -n "options/parameters" ftp://10.100.110.83 ....other options

regards
ygemici

Last edited by ygemici; 10-22-2013 at 05:19 AM..
# 11  
Old 10-22-2013
is it possible to capture the 3 digit return code of ftp commands in a local variable inside a shell script?

Code:
ftp remoteserver << ftp 
    quote USER uid
    quote PASS pass
    prompt
    cd remote_directory
    mput file.txt
    bye
ftp

in the above script, if cd command returns 550 in case of failure and 226 in case of success. same way mput also returns.. how cn i capture these return codes.
# 12  
Old 10-23-2013
I would suggest using a different delimeter to mark the in-line text of the "here" document. Using ftp could be rather confusing. Perhaps something like:-
Code:
ftp remoteserver << EOFTP
    quote USER uid
    quote PASS pass
    prompt
    cd remote_directory
    mput file.txt
    bye
EOFTP

..... would be clearer.

Remember that EOFTP would have to be the first non-tab character of the line to end the in-line text.




Robin
# 13  
Old 10-23-2013
Quote:
Originally Posted by rbatte1
I would suggest using a different delimeter to mark the in-line text of the "here" document. Using ftp could be rather confusing. Perhaps something like:-
Code:
ftp remoteserver << EOFTP
    quote USER uid
    quote PASS pass
    prompt
    cd remote_directory
    mput file.txt
    bye
EOFTP

..... would be clearer.

Remember that EOFTP would have to be the first non-tab character of the line to end the in-line text.




Robin
ok can u answer the below thread.. any idea..

here
# 14  
Old 10-23-2013
Quote:
Originally Posted by Little
is it possible to capture the 3 digit return code of ftp commands in a local variable inside a shell script?

Code:
ftp remoteserver << ftp 
    quote USER uid
    quote PASS pass
    prompt
    cd remote_directory
    mput file.txt
    bye
ftp

in the above script, if cd command returns 550 in case of failure and 226 in case of success. same way mput also returns.. how cn i capture these return codes.
Code:
# a=$(./unix.com-ftp.sh 10.100.110.83 cd 4) && echo $a
250
# a=$(./unix.com-ftp.sh 10.100.110.83 get 2) && echo $a
226
# a=$(./unix.com-ftp.sh 10.100.110.83 cd 34234qwq) && echo $a
550

Code:
#!/bin/bash
# /********************************************************\
# *     unix.com ftp return-codes                          *
# *     @ygemici                                           *
# *     uses $HOME/.netrc for auto-login                   *
# \********************************************************/
arrayX=($@ ); ftpcmd="${arrayX[@]:1}";ok=0
echo "$ftpcmd"|/usr/bin/ftp -v "${arrayX[0]}"> /tmp/tmpuxXXXX.ftp
for i in get put ; do
echo "$ftpcmd"|grep $i|grep -v m >/dev/null
if [ $? -eq 0 ] ; then
for j in "File receive" "File send" ; do
grep "$j" /tmp/tmpuxXXXX.ftp >/dev/null
if [ $? -eq 0 ] ; then
sed 'N;N;x;$!D' /tmp/tmpuxXXXX.ftp|sed -n '$s/ .*$//p';exit;fi
done
sed 'N;x;$!D' /tmp/tmpuxXXXX.ftp|sed -n '$s/ .*$//p';exit ;fi
done
for i in mget mput mdelete mdir mls; do
echo "$ftpcmd"|grep $i >/dev/null; if [ $? -eq 0 ] ; then ok=1;fi
done
if [ $ok -eq 1 ] ; then
echo;echo "detected interactive command! ftp return code(s) maybe cant be determined!!";
sed 'N;N;x;$!D' /tmp/tmpuxXXXX.ftp|sed -n '$p'
else sed '$!N;$!D' /tmp/tmpuxXXXX.ftp|sed -n '1s/ .*$//p' ; fi

regards
ygemici
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Specifying port for ftp when using .netrc

Hi, does anybody know if it is possible to specify a particular port for an FTP address within a .netrc file ? i have a script which opens the ftp to a machine and then instigates .netrc to login etc.. within .netrc i need it to go to a particular port to enable me to automate the dropping of... (2 Replies)
Discussion started by: forefather1977
2 Replies

2. UNIX for Dummies Questions & Answers

Performing Batch ftp without .netrc

How can I supply the userID/password when executing FTP in the batch mode? Using .netrc is not an option (prohibited per Corporate Policy). Thank you in advance. (1 Reply)
Discussion started by: compaamat
1 Replies

3. Shell Programming and Scripting

FTP script to login and list files to log file

Hi Guys I did a forum search for "ftp scripts" Looked at 8 pages and didnt see anything that would help. Most seem to be logging into a ftp server and transfering files. What I need to do is login to a FTP server. Goto a folder and list it so it showes newest files first. It would be nice to... (4 Replies)
Discussion started by: voorhees1979
4 Replies

4. Shell Programming and Scripting

Automating ftp without .netrc

I'm writing a script which needs to run under an 'automation' account and there is already a .netrc machine definition for the server I need to connect to. If I create a new machine entry in the .netrc with a different account this will, of course, be ignored and the ftp session will connect to... (3 Replies)
Discussion started by: DeepakS
3 Replies

5. AIX

.netrc and Automatic ftp problem

Guy's We have two AIX servers Server1 and Server2 and we have created user1 in Server1 and Server2 ... and .netrc file was confiured under /home/user1 with the below line machine server2 login user1 password abc1234567 -rw------- 1 user1 staff 159 Sep 28 2004 .netrc ... (7 Replies)
Discussion started by: ITHelper
7 Replies

6. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

7. Shell Programming and Scripting

FTP/nmap/.netrc

So... I'm trying to script and FTP Backup of some files from openVMS Alpha machine to a Unixware 7 machine. I decided to use .netrc to do all the FTP actions however when I send the nmap command. It pretty much gets ignored while even other things such "ascii", "case" etc.. get respected... (0 Replies)
Discussion started by: thesubmitter
0 Replies

8. AIX

.netrc and ftp

Hello all, I am using a .netrc to automatically access an ftp host. Here is the line I use... machine 412.blank.com login nw\mylogin password ******* when I use this command... ftp 412.blank.com I get... Connected to 412.blank.com. 220 server_7 FTP server (EMC-SNAS: 5.5.25.2)... (4 Replies)
Discussion started by: magikalpnoi
4 Replies

9. UNIX for Dummies Questions & Answers

.netrc and ftp issue

Ok guys (gals?) Im new here as a member, but have come here many times to find answers to questions. Have played with Unix (ATT Sys 5) and now Linux (RH)... I told myself I wanst going to ask for help on the current project..but.. I am down to what I think is the last issue: (and I KNOW the... (3 Replies)
Discussion started by: txdave
3 Replies

10. UNIX for Dummies Questions & Answers

.netrc multiple ftp jobs to same machine

I have an ftp user, which has been setup to run ftp jobs to a specific machine (different jobs). for the first job i created .netrc in the ftp users home directory and added the appropriate commands machine FTPBOX01 login user1 password xxx macdef init etc etc get file bye I use the... (3 Replies)
Discussion started by: hcclnoodles
3 Replies
Login or Register to Ask a Question