Skip to content
Advertisement

ftp: Login to server, auto-change remote dir, then bring user input?

I’m using “ftp” with the login credentials in .netrc for auto-login to a remote FTP server. The thing is that I always need to “cd” to my remote working dir manually each time I log in. Is there any way to “cd” automatically on connection, and then bring the user input after the directory was changed?

Advertisement

Answer

The solution is to defined a macro named init

Extract from man netrc

 macdef name
           Define a macro.  This token functions like the ftp macdef command functions.  
           A macro is defined with the specified name;
           its contents begin with the next .netrc line and continue until a null line
           (consecutive new-line characters) is encountered.  If a macro named
           init is defined, it is automatically executed as the last step in
           the auto-login process.

A example of .netrc with a init macro :

machine 192.168.19.5
login  theusername
password theSECRETpassword
macdef init
pwd
!pwd
lcd /tmp
cd /tmp
pwd
!pwd

machine 192.168.19.6
../..
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement