Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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
add comment

2 Answers

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
binary

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.