Method: MCMD::NetTools.ftp

Defined in:
lib/nysol/mnettools.rb

.ftp(ip, uid, from, to, secret) ⇒ Object

Ftpファイル送信



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/nysol/mnettools.rb', line 109

def self.ftp(ip,uid,from,to,secret)
	sts =false
	unless File.file?(from) then
		raise "File #{from} not found. "
	end
	if to =~ /\/$/ then
		cmdRun(ip,uid,"mkdir -p #{to}")
	else
		cmdRun(ip,uid,"mkdir -p #{File.dirname(to)}")
	end	
	temp=MCMD::Mtemp.new
	fn = temp.file
	File.open("#{fn}","w"){|fw|
		fw.puts "open #{ip}"
		fw.puts "user #{uid} #{secret}"
		fw.puts "prompt"
		fw.puts "bi"
		fw.puts "put #{from} #{to}"
		fw.puts "bye"
	}

	@@retry_scp.times{
		sts = system("ftp -n < #{fn} > /dev/null")
		#sts = system("ftp -n < #{fn} ")
		break if sts
		sleep 2**i
		MCMD::warningLog("FTP SEND RETRY(#{i+1}/#{@@retry_scp})")		
	}
	MCMD::warningLog("send ERROR by ftp") unless sts
end