0

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")
aidan
  • 9,310
  • 8
  • 68
  • 82
zulqarnain
  • 1,695
  • 1
  • 16
  • 33
  • 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? – fotanus Jun 03 '13 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. – zulqarnain Jun 03 '13 at 18:17

1 Answers1

9

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.

zulqarnain
  • 1,695
  • 1
  • 16
  • 33