9
Mrz
2005

How to use ftp in combination with .netrc

After answering a number of questions regarding automatic FTP on
Unix-systems and the involvement of .netrc in it, I created this
little guide.

Permissions and location of the .netrc

The .netrc should be in your home-directory and the permissions on
the file should be unreadable for everybody except the owner:

[~] edwin@k7>ls -al .netrc

-rw-------  1 edwin  wheel  246 Aug 27 16:14 .netrc

You can set to these settings with chmod 600 .netrc.

Layout of the .netrc

Machine definitions

The first part of the .netrc is filled up with host-definitions:

machine ftp.freebsd.org
	login anonymous
	password edwin@mavetju.org

machine myownmachine
	login myusername
	password mypassword

What it is saying now is nothing more than "If you connect to
ftp.freebsd.org, login as anonymous and use
edwin@mavetju.org as password." and "If you connect to

myownmachine, login as myusername and use mypassword
as password.".

Macro definitions

This part of the .netrc consists of macros which can be used to
perform automated tasks:

macdef uploadtest
	cd /pub/tests
	bin
	put filename.tar.gz
	quit

macdef dailyupload
	cd /pub/tests
	bin
	put daily-$1.tar.gz
	quit

Keep in mind that there should be an empty line after the last
macdef statement. If you don't do this, ftp will complain about it.

The first one is saying "Go to the /pub/tests directory, switch to
binary mode, put a file there and quit it". The second one is saying
the same, except that the name of the file is based on a parameter
on the macro-call (see Usage of the .netrc for more about
this).

Usage of the .netrc

Macros can be called from both inside ftp:

[~] edwin@k7>ftp myownmachine
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
220 myownmachine FTP server (Version 6.00LS) ready.
331 Password required for myusername.
230 User myusername logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> $ uploadtest
cd temp
250 CWD command successful.
put filename.tar.gz
local: filename.tar.gz remote: filename.tar.gz
150 Opening BINARY mode data connection for 'filename.tar.gz'
100% |**************************************************|  1103       00:00 ETA
226 Transfer complete.
1103 bytes sent in 0.01 seconds (215.00 KB/s)
quit
221 Goodbye.

...or from on the command-line:

[~] edwin@k7>echo "\$ uploadtest" | ftp myownmachine
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
100% |**************************************************|  1103       00:00 ETA

There is not much information here, because ftp doesn't expect a
terminal here. If you use ftp -v, there will be more output.

An example with arguments is

[~] edwin@k7>echo "\$ dailyupload `date +'%Y%m%d'`"
$ dailyupload 20010827
[~] edwin@k7>echo "\$ dailyupload `date +'%Y%m%d'`" | ftp myownmachine
ftp: connect to address ::1: Connection refused
Trying 127.0.0.1...
100% |**************************************************|  1103       00:00 ETA

It will upload the file daily-20010827.tar.gz.

Debugging of ftp-sessions

What can go wrong

The only problems I've encountered are

  • People forgetting to add an empty line after the last macdef statement.
  • People with incorrect permissions on the .netrc-file.

Debugging

  • If you are running the macro via the commandline, use the -v
    option to see more output.
  • If you run ftp with the -d option you will get all commands
    send to the ftpd.

                                       
$Id: netrc.php,v 1.7 2002/11/17 08:31:15 mavetju Exp $


original link
logo

vireas

Suche

 

Aktuelle Beiträge

C i s c o  V...
can get always the latest version of C i s c o  V...
vireas - 12. Jul, 11:07
WM5: Custom text on today...
You can set a small custom text message on the bottom...
vireas - 15. Mai, 21:44
WM5: Increase Performance...
Boost Windows Mobile 5 performance up to 20 percent [HKLM\System\Stor ageManager\FATFS]...
vireas - 15. Mai, 21:42
WM5: Speed Up your Pocket...
This tweak might help improving visual performance...
vireas - 15. Mai, 21:41
Windows Ordner
-Es ist nicht möglich unter Windows einen Ordner anzulegen...
vireas - 22. Feb, 13:37

Archiv

März 2005
Mo
Di
Mi
Do
Fr
Sa
So
 
 3 
 4 
 5 
 6 
 7 
 8 
10
11
12
13
14
15
16
17
19
20
21
22
23
24
25
26
27
28
30
31
 
 
 
 

Status

Online seit 7702 Tagen
Zuletzt aktualisiert: 12. Jul, 11:07
vireas-plug

KnowHow
KnowHow - Mobiles
Tools
Profil
Abmelden
Weblog abonnieren