0

I'm currently creating .csv files from a SQL view and writing to

#{Rails.root}/public/

which works no problem. In addition, I need to write these generated files to a Windows share in the form of:

\\NAME-APP.enterprise.company.com\Files

I've tried Net::SCP.upload, Net::SFTP.start, FileUtils, rsync, and even Dir.entries('share url here)` just to see if I can see anything in the folder, which generally results in

No such file or directory @ dir_initialize

I can map my local computer to the Windows share point, in the form of:

smb://NAME-APP.enterprise.company.com/Files

but manually dragging and dropping to there isn't an acceptable solution in this case.

Feel like I've hit a wall and may be overlooking something. Have stumbled across this post but to no avail: How do I address a UNC path in Ruby on Windows?

Any advice on this is greatly appreciated.

Edit:

FileUtils.cp_r('/Volumes/Macintosh HD/Users/davidpardy/development/ror/sbb/oct31week/1a/FST-Export/public/1538791_new.txt', '\\\\NAME-APP\\Files')

doesn't return an error, but doesn't upload the .txt file to Files.

Community
  • 1
  • 1
Nubtacular
  • 1,367
  • 2
  • 18
  • 38
  • Make sure you are using the mount path instead of `smb://...`. If you're on a mac this will look something like `/Volumes/Files...` – Sean Huber Nov 03 '16 at 18:46
  • Well the `smb` portion would only be for Windows, since that's where I'm trying to get files to. Did you mean explicitly state the location of the .txt files on Mac? ie `/Volumes/mycomp/dev/RailsApp/public/whatever.txt. Updated my initial question with some extra stuff. – Nubtacular Nov 03 '16 at 19:20
  • 1
    Right, `smb://...` is just the server address, but you want to know the path you've mounted it to on your file system. Open up the terminal and run the command `mount`. You should see something like `//NAME-APP/Files on /Volumes/my_mount_folder (smbfs, nodev, ...)` – Sean Huber Nov 03 '16 at 19:26
  • Ahhh interesting, so it should be `FileUtils.cp_r('/Volumes/Macintosh HD/Users/davidpardy/development/ror/sbb/oct31week/1a/FST-Export/public/1538791_new.txt', '/Volumes/OasisFlatFiles')` . Just ran that and it worked! You rock man! Feel free to post as an answer and I'll upvote it. – Nubtacular Nov 03 '16 at 19:41
  • Awesome! I posted the answer below for you to accept. I'm glad you got passed the wall ;-) – Sean Huber Nov 03 '16 at 19:45
  • Haha man I was pulling my hairs out. Definitely learned something new here so that's what matters! – Nubtacular Nov 03 '16 at 19:46

1 Answers1

1

The solution is not to use FileUtils.cp_r(source_file, 'smb://...') because smb://... only represents the server address, not the mount folder on your filesystem.

In the terminal, run the mount command to find the path of the mount folder, which is what you'll use in ruby, e.g., FileUtils.cp_r(source_file, '/Volumes/mount_folder_here...').

Sean Huber
  • 3,945
  • 2
  • 26
  • 31