-
Notifications
You must be signed in to change notification settings - Fork 0
/
mediaMove.rb
66 lines (56 loc) · 1.7 KB
/
mediaMove.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
require 'net/scp'
# Upload local file/directory to remote directory
# ruby mediaMove.rb <file/folder> <new name> <tv/movies>
# Requires two arguments
# mediaObject = file/folder to move from local to remote
# newName = new name of file/folder on remote file system (keeps names within dir)
# destination = switch between two paths (tv or movies in my case)
mediaObject = ARGV[0]
newName = ARGV[1]
destination = ARGV[2]
# Add vars here
# Need vars to be passed to methods
# Method for moving single file from local to remote
# Edit credentials for remote host
def fileUp(mediaObject, newName)
File.open(mediaObject) do |f|
Net::SCP.start(remoteServer, login, :password => password) do |scp|
scp.upload mediaObject, remotePath + newName,
:verbose => true
end
end
end
# Method for recursively moving a directory from local to remote
# Edit credentials for remote host
def dirUp(mediaObject, newName)
Dir.open(mediaObject) do |f|
Net::SCP.start(remoteServer, login, :password => password) do |scp|
scp.upload mediaObject, remotePath + newName,
:recursive => true, :verbose => true
end
end
end
# Pre sort media objects destination
if destination != 'tv' || 'movies'
puts 'Error: specify destination (movies/tv)'
elsif
destination == 'tv'
remotePath = tvPath
puts 'Transferring to TV'
else
remotePath = moviesPath
puts 'Transferring to Movies'
end
# Main logic on how to send media object
if mediaObject == nil
puts "Specify a file or folder, Turkey!"
elsif
Dir.exists?(mediaObject)
dirUp(mediaObject, newName)
puts "Directory Succeffuly Uploaded!"
elsif
File.exists?(mediaObject)
fileUp(mediaObject, newName)
puts "File Successfully Uploaded!"
end