Trying to understand and download file with SFTP.download in Ruby/Rails - ruby-on-rails

I'm trying to download a file into a Rails application using the SFTP method with sftp.download!('path/to/remote/folder/#{filename}', 'path/to/local/folder)
The full methods:
def missouri
sftp = Net::SFTP.start('host.name', '<username>', password: '<password>')
sftp.dir.entries('/path/to/remote/folder/') do |entry|
sftp.download!('/path/to/remote/folder/#{entry.name}.txt', '/Users/<me>/local/folder/')
end
end
I get an error:
RuntimeError (open /path/to/remote/folder/filename.txt: no such file (2))
If I take away the file extension (txt), I get the error:
Errno::EACCES (Permission denied # rb_sysopen - /Users/<me>/local/folder/)
When I 'drill' down to that part and run this method, I get a return of the NET::Sftp object with all of it's attributes but no actual download. The SFTP I'm trying to access is an ASPX.human page and the path I'm trying to download the file is within the file structure of the remote site so I'm not sure if I'm trying to access the wrong path?
If I go to the actual SFTP, I can clearly see a file sitting there.

The comment you added after your question makes we wonder about unix rights. Is your script launched by a user that is allowed to write on the destination local directory?
Said differently, what is the output of the following shell command?
ls -l /path/to/remote/folder
And what are the user/group used your script?
By the way, one thing strange in your code:
sftp.download!('/path/to/remote/folder/#{entry.name}.txt'
should be:
sftp.download!("/path/to/remote/folder/#{entry.name}.txt"
Otherwise entry.name would not be replaced.

Related

Getting Errno::ENOENT (No such file or directory # rb_sysopen) while trying to - File.open('condoleads1.json')

I'm trying to open a JSON file (using ruby on rails) that's on my computer titled "condoleads1.json". When I run the command - File.open('condoleads1.json'),I get the following error :Getting Errno::ENOENT (No such file or directory # rb_sysopen)
The file has to be in the directory where you run the program (formally, the working directory), not just anywhere on your computer. If you really do need to access a file that's somewhere else, use its full path (like C:\Users\the\the.txt or /home/the/the.txt) and not just the name

How can I create an API directory using the Google App Engine's Service Generator?

I've been following the instructions on Google's Doc. ->
https://cloud.google.com/appengine/docs/java/endpoints/consume_ios#Java_Compiling_the_client_library_generator_and_generating_your_library
But I cannot get past step 5 (Compiling the client library generator and generating your library)
/Users/username/Library/Developer/Xcode/DerivedData/ServiceGenerator-btnyogexyyjtgrgbfjqddcedmkls/Build/Products/Debug/ServiceGenerator \ /Users/username/Documents/discoveryFileName.discovery \ --outputDir /API
However, I get the error - "ERROR: An output directory is required".
Any ideas?! I clearly put the output Directory in there. Would this error occur if the discovery file was not in the correct format?
I've tried many different output directories as well
Please!!
I see you're using --outputDir /API -- that is, trying to create the directory right under the root directory in your filesystem.
The example uses, instead, --outputDir ~/API -- that ~ sign just before the / means it creates the directory inside your home directory (in Unix-like systems).
You may miss permissions required to create directories at the top of your filesystem, while you likely have such permissions within your home directory. Therefore, I would recommend doing exactly what the example suggests -- keeping the ~ (tilde) there, rather than removing it.

trigger.io [Error 5] Access is denied

I just recently updated to the new version of forge, did not change anything on my setting and when I went to build my app I got an error that said it could not find the file..
so I made the copy of aapt file and put it in a directory where trigger said it was looking (the docs said trigger.io should have moved this file for me already but Im guessing it did not)
After I moved this file and ran the build again it looked like it found the file but now I get [Error 5] Access is denied.
I have checked the permissions on the folder as I am the admin and I have full permissions and I have launched trigger as an administrator and still nothing.
Thanks.
So again from what I can tell this is a problem with the python script that calls aapt.
When you look at the script it points only to aapt, this means its looking for a directory and not the aapt.exe file itself so the first thing that happens is
1) forge says it cant find the aapt directory, this is why you are getting the error message "cant find aapt tool"
2) by adding the directory you would get the access denied because then the script is trying to run all these commands on just the directory (this was the problem I ran into), by making the change below you do not need to create a directory, just leave everything how it is but add the exe and it should work
After doing some testing I found that by adding .exe to the pythong script in android_tasks.py the build was able to run successfully
if you look on line 35 of android_tasks.py and change 'appt' to 'appt.exe' it should build for you
this is what it looks like for me
path.join(sdk, 'build-tools', '*','aapt.exe')
Hope this helps

how to execute binary on heroku?

I try to execute a binary on heroku. I follow this blog : http://www.verrot.fr/2010/02/24/executing-binary-files-with-ruby-on-rails-and-heroku/ :
I have the following code :
#exec = IO.popen("#{Rails.root}/bin/aapt version")
#result = #exec.gets
puts #result
I've got the following error on heroku while it's working on local rails server :
command not found: app/bin/aapt version
Have you got any idea on a way to do that ? Or if you already done that ?
How I have gotten this to work, but be warned, Heroku does not support this solution. The direct quote from Heroku Support is "you are on your own."
Create a bin directory in your application.
Add Debian etch amd64 binaries to this directory. For example, add application called mongodump.
Have your code execute system call. Example (note the lack of path):
system "bin/mongodump --help"
A true or false will be returned from the system call.
Did you make sure the permissions on your local binary allow execution? Git is permissions-aware. If not, you need to make sure the file allows executable permissions (modify the permissions if you must), then add the modified file to git and repush to heroku before trying again. Keep in mind that the user heroku will use to execute the file may or may not be the owner, so you may need to play with them in order to get heroku to recognize it. Just chmod 777 bin/executable_name as a last resort.

Permission denied using wicked_pdf from ruby on Windows 7

ruby -v = 1.9.1p378; rails -v = 2.3.8
wkhtmltopdf works just fine from the command line - generates a PDF. The path to the .exe is in the %PATH% variable as well as specified properly in the /config/initializers/wicked_pdf.rb file.
Set up the controller action to handler .pdf format but I get the following error
Permission denied - c:/Ruby191/bin/wkhtmltopdf - -
C:/Ruby191/lib/ruby/1.9.1/open3.rb:67:in 'spawn'
C:/Ruby191/lib/ruby/1.9.1/open3.rb:67:in 'popen3'
C:/work/hello/vendor/plugins/wicked_pdf/lib/wicked_pdf.rb:21:in 'pdf_from_string'
C:/work/hello/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:28:in 'make_pdf'
C:/work/hello/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:39:in 'make_and_send_pdf'
C:/work/hello/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:13:in 'render_with_wicked_pdf'
... controller related code follows ...
I've tried putting the wkhtmltopdf.exe (and related files) in various directories and checked permissions on those dirs to allow full control to Everyone.
Any help as to where the permission problem might be would be appreciated.
As a note: this works just fine run from the command line ruby pdftest.rb
require 'open3'
Open3.popen3('/bin/tools/wkhtmltopdf.exe http://www.google.com/ g.pdf')
The PDF is created with remarkable speed and no permission problems. Could be a problem with the account running WEBrick but I would think that would be solved by giving Everyone permission on the dir that has wkhtmltopdf.exe
I had to answer my own question. I'm stupid sometimes you know.
In the :exe_path variable I had put the path to the exe not including the name of the exe. when I added wkhtmltopdf.exe to the end of my existing path I fixed the permissions issue.
Posted in case someone else has the same issue.

Resources