我正在编写一个脚本,使用模块net/scp
将文件夹从客户端上传到服务器但我不知道如果服务器上尚不存在,则使用ruby自动创建新文件夹。我该怎么做?如何使用net/scp
在服务器上运行任何Ruby脚本?
这是我到目前为止的代码:
def upload(fileName_upload,pathLocalFolder,pathRemoteFolder)
pathLocalFolder=pathLocalFolder + '/'+fileName_upload
Net::SCP.start($host, $username, :password => $pass_Word) do |scp|
scp.upload! pathLocalFolder, pathRemoteFolder
channel = scp.upload(pathLocalFolder, pathRemoteFolder)
channel.wait
end
def uploadFolder(pathLocalFolder,nameFolderInServer)
# I want to create a folder on the server, but I don't know how to do it
#Dir.mkdir(nameFolderInServer) unless File.exists?(nameFolderInServer)
Dir.glob(pathLocalFolder) do |item|
name=File.basename item,''
if File.directory?(name)
uploadFolder(pathLocalFolder+'/'+name,name)
end
if File.file?(name)
upload(name,pathLocalFolder,$remote_Path+'/'+nameFolderInServer)
end
end
end