如何将二进制文件或任何文件传输到远程服务器?-红宝石 [英] How to transfer a binary file or any file to a remote server? - Ruby
问题描述
这种情况是我正在尝试编写一个服务器脚本,该脚本接受来自客户端的文件传输.我想出了如何使用TCP协议与服务器建立连接和相互连接的方法.但是我想知道如何在ruby中传输二进制文件?
The situation is that I'm trying to write a server script that accepts file transfers from a client. I figured out how to make and connect to and from the server using the TCP protocol. However I was wondering how do you transfer a binary file in ruby?
我的意思是您可以打开一个二进制文件,但是要传输该文件需要什么步骤?TCP流的想法吗?UDP呢?
I mean you can open a binary file, but what steps are necessary to be able to transfer it? Is TCP stream idea? What about UDP?
推荐答案
我想我找到了解决方案.
I think I found a solution.
使用SFTP,我可以通过SSH连接将文件上传到服务器:
Using SFTP, I can upload files over an SSH connection to the server:
require 'net/sftp'
Net::SFTP.start('host', 'username', :password => 'password') do |sftp|
# upload a file or directory to the remote host
sftp.upload!("/path/to/local", "/path/to/remote")
# download a file or directory from the remote host
sftp.download!("/path/to/remote", "/path/to/local")
end
但是,这并不是我真正想要的,因为以上内容依赖于使用SSH.我希望它是独立的.
However this isn't really what I was looking for as the above relies on using SSH. I was hoping it to be independent.
这篇关于如何将二进制文件或任何文件传输到远程服务器?-红宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!