How to upload binary file?

47 views
Skip to first unread message

optman

unread,
Sep 6, 2007, 5:45:18 AM9/6/07
to Capistrano
when use the put() file from local machine to remote machine, the
result file bytes is less. Is that something related to binary mode?

btw, where is define of File.read()? I search all the doc and code,
and can't found the definition.

I am a freshman to ruby, there are many obstacles to run Capistrano .

Jamis Buck

unread,
Sep 6, 2007, 9:42:44 AM9/6/07
to capis...@googlegroups.com
On 9/6/07, optman <opt...@gmail.com> wrote:
>
> when use the put() file from local machine to remote machine, the
> result file bytes is less. Is that something related to binary mode?

If you're on Windows, then yeah, that's the problem. I've fixed this
bug in the latest preview release, and I hope to release cap 2.1 final
"soon".

> btw, where is define of File.read()? I search all the doc and code,
> and can't found the definition.

It's a standard Ruby method, defined in the Ruby sources themselves.

- Jamis

optman

unread,
Sep 6, 2007, 11:30:51 AM9/6/07
to Capistrano
yes, I am on windows. I will give cap 2.1 preview a try tomorrow.

thanks!

optman

unread,
Sep 7, 2007, 12:54:58 AM9/7/07
to Capistrano
I have try the latest cap preview release, don't work neither.

maybe it is my fault, I use the code like this.

put(File.read("#{tar_file}"), "#{tar_file}")

Is there other way to upload file to remote server?

Jamis Buck

unread,
Sep 7, 2007, 1:41:38 AM9/7/07
to capis...@googlegroups.com
Yeah, you can't do File.read() on Windows, because it reads in text
mode. You need to do this:

body = File.open(tar_file, "rb") { |f| f.read }
put(body, tar_file)

- Jamis

optman

unread,
Sep 7, 2007, 3:32:24 AM9/7/07
to Capistrano
change to File.open(), everything is fine now! alought it is not a
good idea to read all the contents in a whole, it work!

thanks!

Reply all
Reply to author
Forward
0 new messages