Question

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")
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top