Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I typically use the bash command line when I need to FTP something. I have found that certain FTP servers are not set to binary mode by default and unless I remember to do so, the file sent will be corrupt. Is there a way to set binary mode automatically every time I access a remote ftp server?

share|improve this question

migrated from Dec 13 '09 at 19:34

This question came from our site for professional and enthusiast programmers.

Why not issue 'bin' each time you do an upload? – t0mm13b Dec 13 '09 at 19:17
Very good question! I have just strace'ed the ftp command. I see that ftp reads .netrc, but unfortunately netrc supports only username/passwd AFAIK. – Vokuhila-Oliba Dec 13 '09 at 19:32
Steven - if someone answers this question with an expect script, would you then have to migrate that answer back to SO? – galaxywatcher Dec 13 '09 at 19:44
up vote 2 down vote accepted

If you want to use ftp, then you can put arbitary commands into the netrc by defining a macro. If the macro is called init, then it will be automatically executed, like this

machine server
login user
password password
macdef init

Any commands between the macdef line and the blank line will be executed as soon as the login is complete.

share|improve this answer
Thanks. This is exactly the answer I was looking for. I simply created .netrc and added binary, tested, and it works as you said. However, I am really liking ncftp now, which will be my new ftp client. – galaxywatcher Dec 14 '09 at 7:29

Use ncftp, which defaults to binary.

share|improve this answer
Thanks for the ncftp tip. I love the bookmark feature as well. – galaxywatcher Dec 13 '09 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .