1

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")
2
  • 2
    are you sure that this file is in the correct place, and this is the correct path? is testupload.zip calling the method zip in the testupload object? maybe you need to remove the testupload.zip from the target patch? Commented Jun 3, 2013 at 18:13
  • Even if I remove that it still doesn't work. I think the problem is it's detecting it as full path instead of relative path from the user's home directory. Commented Jun 3, 2013 at 18:17

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.