Skip to content

nixCraft

Linux Tips, Hacks, Tutorials, And Ideas In Blog Format

  • About
  • Howtos and tutorials
  • Linux Shell Scripting Tutorial
  • RSS/FEED
  • DONATIONS
  • Search

nixCraft

Linux Tips, Hacks, Tutorials, And Ideas In Blog Format

nixCraft

Tag: ftp auto login

Increase productivity with FTP autologin and macros

last updated February 28, 2006 in Categories Automation, Backup, CentOS, Debian Linux, Howto, Linux, programming, RedHat/Fedora Linux, Ubuntu Linux

You may use many macros under office packages. However, your ftp client also supports macros. You can use ~/.netrc – user configuration file. The .netrc file contains login and initialization information used by the auto-login process and stores macros information. It resides in the user’s home directory.

Turn on FTP client auto login

You need to add username and password to file ~/.netrc. Open config file using a text editor such as vi:
$ vi ~/.netrc
Append or add following lines to it:
machine ftp.myserver.com login USERNAME password PASSWORD
Save file and exit to shell prompt. Make sure, only owner can read the file:
$ chmod 0600 ~/.netrc
To connect type command:
$ ftp ftp.myserver.com

FTP Macros

Now let us say every time you connected to ftp server you would like to switch to binary mode and turn off prompt as well as go to directory /pub/data/backup/rdbms/dump/. You can create a macro to automate all these three steps:

i) Open ~/.netrc ftp configuration file:
$ vi ~/.netrc
ii) Define a macro
You need to use the following syntax:

macdef macro-name1
command1
command2

macdef macro-name2
command1
command2

Please note that each macro definition ends with a null line (consecutive new line characters in a file or carriage returns from the terminal). There is a limit of 16 macros and 4096 total characters in all defined macros. Macros remain defined until a close command is executed.

Append following text to .netrc file:

macdef FOO
bin
prom
cd  /pub/data/backup/rdbms/dump/
ls 

Save and close the file. Now connect to ftp server:
$ ftp ftp.myserver.com
Output:

Connected to ftp.myserver.com
220 ftp.myserver.com NcFTPd Server (licensed copy) ready.
Remote system type is UNIX.
Using binary mode to transfer files.

To execute a macro FOO type the command:

ftp> $ FOO

Output:

bin
200 Type okay.
prom
Interactive mode off.
cd /pub/data/backup/rdbms/dump/
250 "/pub/data/backup/rdbms/dump/" is new cwd.
ftp> ls

Further readings:

=> ftp command man page

6 Comments

Cool Linux penguin shirt

Featured Articles

  • 1
    30 Cool Open Source Software I Discovered in 2013
  • 2
    30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
  • 3
    Top 32 Nmap Command Examples For Linux Sys/Network Admins
  • 4
    25 PHP Security Best Practices For Linux Sys Admins
  • 5
    30 Linux System Monitoring Tools Every SysAdmin Should Know
  • 6
    40 Linux Server Hardening Security Tips
  • 7
    Linux: 25 Iptables Netfilter Firewall Examples For New SysAdmins
  • 8
    Top 20 OpenSSH Server Best Security Practices
  • 9
    Top 25 Nginx Web Server Best Security Practices
  • 10
    My 10 UNIX Command Line Mistakes

Sign up for my newsletter

Sign up for my newsletter



RSS Recently updated

  • Debian Linux 9.8 released and here is how to upgrade it
  • How to ping and test for a specific port from Linux or Unix command line
  • How to find a folder in Linux using the command line
  • Debian Linux 9.7 released and here is how to upgrade it
  • Ubuntu Enable & Set up Automatic Unattended Security Updates
  • Linux hide processes from other users and ps command
  • Understanding Bash fork() Bomb :(){ :|:& };: code
  • vim-plug: A beautiful and minimalist vim plugin manager for Linux/Unix users
  • Linux / UNIX: Bash Script Sleep or Delay a Specified Amount of Time
  • KSH redirect stdout and stderr to a file on Linux or Unix

Corporate Patron

  • Linode
  • Cloudflare
  • Prospect One
nixCraft @2000-2019 nixCraft. All rights reserved.
  • PRIVACY
  • TERM OF SERVICE
  • CONTACT/EMAIL
  • DONATIONS
  • Search