.netrc does not execute mput command

Hi all :smiley:

i' ve a script running on freebsd system:

echo "Start FTP Transfer"

cd /tmp/elaboralog

ftp -i 192.168.27.147 2100 > /tmp/elaboralog/ftp_log_phase2

That call .netrc

machine 192.168.27.147
login user
password 12345
macdef backup
binary
cd tmp/elaboralog
mput *-file.txt
quit

I can see the host authenticating successfully on the server ftp but hanging for ftp commands.:confused:

It seems that the .netrc stops at 'cd' command. :wall:

Maybe the slash missing in front of tmp?

TnkX for answer. :slight_smile:
But.. no i've tryied in both ways...:frowning:

Perhaps try putting prompt on the line before the mput ?

(and you really should have the / before tmp.

Sorry
i've also tryed with "prompt" and "prompt off" ... no way :wall:

I know the behaviour can vary between client implementations of ftp... (and so in what you should have in .netrc ...) look at the man pages of your release (netrc (4)) to see if we missed something

Also, you've defined the macro "backup". Where did you ever call it?

Connected to myserver1
220 myserver1 FTP server (Version 4.2 Fri May 2 12:48:10 CDT 2008) ready.
331 Password required for root.
230-Last unsuccessful login: Thu Dec 09 21:16:11 NFT 2010 on ftp from myserver2
230-Last login: Fri Sep 30 12:53:58 DFT 2011 on ftp from myserver2
230 User root logged in.
ftp> $ backup
cd /tmp
250 CWD command successful.
pwd
257 "/tmp" is current directory.
prompt
Interactive mode off.
mput *-file.txt
200 PORT command successful.
150 Opening data connection for 1-file.txt.
226 Transfer complete.
28960 bytes sent in 0.001277 seconds (2.215e+04 Kbytes/s)
local: 1-file.txt remote: 1-file.txt
quit
221 Goodbye.

Just curious, but is there any compelling reason not to use scp for this?

Hi i've removed the macro and now this is the new output:

Connected to 192.168.27.147 (192.168.27.147).
220 TYPSoft FTP Server 1.11 ready...
Unknown .netrc keyword put
Unknown .netrc keyword /tmp/elaboralog/20110928-totale.txt
Unknown .netrc keyword quit
331 Password required for nsm_ftp.
230 User nsm_ftp logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

You can keep the macro. You just need to call it.

ftp -i 192.168.27.147 2100 << ! > /tmp/elaboralog/ftp_log_phase2
$ backup
!

And the compelling reasons for not using scp? :slight_smile:

Because of the customer is 'compelling' what i have to do :b::D;)

And the customer, as we know, is always right :smiley:

I was asking only as it's so long since I touched a .netrc file, I've forgotten most everything about it and FTP!

We seem to have a fundamental problem here.
The error messages are "Unknown .netrc keyword".

The sole and only purpose of a the file called ".netrc" is to hold the username and password to access a remote ftp server. One line per server:
e.g.
machine myservername login myaccount password mypassword

The commands to ftp should not be in the ".netrc" file.

In essence the answer is:

ftp -i myservername < myfilecontainingcommands > myoutputfile

The "ftp" will read a correctly formatted ".netrc" file to find out the password (providing that the .netrc file is in the right place and has the right permissions).

If this doesn't crack it, please mention what Operating System (and version) and what Shell you are using.

That is not an accurate statement.

It is possible to define macros in the .netrc file, that do contain FTP commands.

The errors the user shows are because the macdef command was removed (but the FTP commands for it were not).

The second code segment in post #1 shows a perfectly valid .netrc file.

@scottn
I see what you mean but the ".netrc" quoted is not valid on normal "ftp" because the "machine" line is split into multiple lines. I didn't notice the "macdef" line ... but I now believe it to be surplus.

Perhaps how the machine line is handled is implementation-specific? It worked fine, as given, on AIX.

I would test it on OS X, but I have nothing to FTP to... I use scp whenever something needs to be copied :smiley:

Just to try ...

what server scp (for win) really 'fast to try' can i download just to do a test... ? ThnX in Adv :smiley:

I haven't used it, but there's WinSCP, that seems to be quite popular.

Is there a problem with the previous suggestion?

Your .netrc file:

machine 192.168.27.147
login user
password 12345
macdef backup
binary
cd /tmp/elaboralog
prompt
mput *-file.txt
quit
(blank line)

Your script:

ftp -i 192.168.27.147 2100 << ! > /tmp/elaboralog/ftp_log_phase2
$ backup
!

winscp? is there also a server version?

---------- Post updated at 09:45 AM ---------- Previous update was at 09:44 AM ----------

This morning i'will be again on the customer office. I'll try... ;):smiley: (TnX very much for support).

---------- Post updated at 10:17 AM ---------- Previous update was at 09:45 AM ----------

IT WORKS!

---------- Post updated at 10:56 AM ---------- Previous update was at 10:17 AM ----------

IT WORKS!!! Thank you very much.
The last line was definitively working. :D;):b:

---------- Post updated at 11:28 AM ---------- Previous update was at 10:56 AM ----------

I don't know why but... the lines just after the ftp command are not executed...

The script:

echo "Inizio trasferimento FTP"

ftp -i 192.168.27.147 2100 << ! > /tmp/elaboralog/ftp_log_fase2

$ backup

echo "Cleaning folder Elaboralog"

rm -f /tmp/elaboralog/$ann_$mes_$gio_*

echo "End phase2 for day $ann_$mes_$gio_" >> /tmp/elaboralog/log_fase2

You missed a closing "!" for the here-document:

echo "Inizio trasferimento FTP"

ftp -i 192.168.27.147 2100 << ! > /tmp/elaboralog/ftp_log_fase2

$ backup
!
echo "Cleaning folder Elaboralog"

rm -f /tmp/elaboralog/$ann_$mes_$gio_*

echo "End phase2 for day $ann_$mes_$gio_" >> /tmp/elaboralog/log_fase2

Tnk U Very Much.
Everything works now.:cool: