문제

I want to upload files to remote sftp server with relative path. For example I want to be able to upload to sftp://myserver.com/FileStore. I've tried using the following code but it does not work: NB: host is myserver.com/FileStore

uri = URI.parse('sftp://' + host)
Net::SFTP.start(uri.host,username,:password=>password,:port=>port) do |sftp|
                    sftp.upload(testupload.zip,"#{uri.path}/testupload.zip")
                end

This is the error I get:

Net::SFTP::StatusException open /FileStore/testupload.zip (2, "no such file")
도움이 되었습니까?

해결책

I've being able to resolve it using the following code:

uri = URI.parse('sftp://' + host)
Net::SFTP.start(uri.host,username,:password=>password,:port=>port) do |sftp|
    sftp.upload(testupload.zip,"./#{uri.path}/testupload.zip")
end

Always assuming that the path after the server name is a relative path from logged on user's home directory.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top