How to set binary mode by default when FTPing to a remote site?

2

1

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?

galaxywatcher

Posted 2009-12-13T19:13:00.830

Reputation: 123

Why not issue 'bin' each time you do an upload? – t0mm13b – 2009-12-13T19:17:50.250

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. – None – 2009-12-13T19:32:36.923

Steven - if someone answers this question with an expect script, would you then have to migrate that answer back to SO? – galaxywatcher – 2009-12-13T19:44:16.640

Answers

3

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.

gorilla

Posted 2009-12-13T19:13:00.830

Reputation: 2 204

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 – 2009-12-14T07:29:42.043

0

Use ncftp, which defaults to binary.

thouis

Posted 2009-12-13T19:13:00.830

Reputation: 101

Thanks for the ncftp tip. I love the bookmark feature as well. – galaxywatcher – 2009-12-13T19:42:23.960