FTP folder creation mkdir problem

R

ruby talk

I log in fine. I move to differnt folders fine. I display everthing
fine, unless i create a directory. I am not well versed in FTP
protocol i see
"aSession.mkdir( dir ) .."
Issues the corresponding server command and returns the result.
In the chm file,
and i tried to understand and incorperate the code from
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/73557?73397-74534
even if i use this code it gives me the error. I only get the error,
if i try to do something after creating the file.

The error?:
Main Texts


1) Login
2) PWD
3) CD
4) Display files & folders
5) Download
6) Upload
7) Make DIR
8) MISS
9) Close session
Enter Number!:7

Enter new folder name:
asdfasdf
Main Texts


1) Login
2) PWD
3) CD
4) Display files & folders
5) Download
6) Upload
7) Make DIR
8) MISS
9) Close session
Enter Number!:4

z:/ruby/lib/ruby/1.8/net/ftp.rb:243:in `getresp': 500 '': command not
understood. (Net::FTPPermError)
from z:/ruby/lib/ruby/1.8/net/ftp.rb:264:in `sendcmd'
from z:/ruby/lib/ruby/1.8/net/ftp.rb:262:in `synchronize'
from z:/ruby/lib/ruby/1.8/net/ftp.rb:262:in `sendcmd'
from z:/ruby/lib/ruby/1.8/net/ftp.rb:723:in `getdir'
from Z:/ftp.rb:31:in `man'
from Z:/ftp.rb:114
Press any key to continue . . .


##############code######
require 'socket'
require 'net/ftp'
def man
choice = -1
while choice!=9
print "Main Texts\n\n\n"
print "1) Login\n"
print "2) PWD\n"
print "3) CD\n"
print "4) Display files & folders\n"
print "5) Download\n"
print "6) Upload\n"
print "7) Make DIR\n"
print "8) MISS\n"
print "9) Close session\n"
while choice<1 || choice>9
print "Enter Number!:"
choice=gets.to_i
end
print "\n"
if choice==1 then
login
choice = -1
elsif choice==2 then
print $ftp.getdir,"\n"
choice = -1
elsif choice==3 then
change_loc
choice = -1
elsif choice==4 then
a=$ftp.dir($ftp.getdir)
a.each do |c|
print c,"\n"
end
choice = -1
elsif choice==5 then
file_down
choice = -1
elsif choice==6 then
file_up
choice = -1
elsif choice==7 then
print "Enter new folder name:\n"
nwfold = gets
$ftp.mkdir(nwfold)
choice = -1
end
end
end
def login # a check to see if it is already connected
ftploc=String.new('')
print "Enter ftp server:\n"
ftploc=gets.strip
begin $ftp= Net::FTP::new(ftploc)
rescue SocketError => e
print "!!!!!Failed connection!!!\n\n"
return 0
end
print "Enter Logon name:\n"
nm=gets.strip
print "Enter password:\n"
pass=gets.strip
begin $ftp.login(nm,pass)
rescue Net::FTPPermError => e
print "!!!!!!Failed to log in!!!\n\n"
$ftp.close
return 0
end
print $ftp.welcome,"\n"
end
def change_loc
print "Enter new location:"
newloc = gets.strip
print "\n"
begin $ftp.chdir(newloc)
rescue Net::FTPPermError => e
print "!!!failed to change directory!!!"
return 0
end
print "Current location ",$ftp.getdir,"\n\n"
end
def file_down
print "\nDown File Menu\n\n1)Binaray\n2)ascii Suggested\n"
op = gets.to_i
print "File to get location/name\n"
from = gets.strip
print "Place to save file\n"
to = gets.strip
if op == 1 then
$ftp.getbinaryfile(from,to)
elsif op == 2 then
$ftp.gettextfile(from,to)
else "If you dont know how to enter a 1 or 2 then you dont get the file\n"
end
print "\n",$ftp.lastresp,"\n"
end
def file_up
print "\nUp File Menu\n\n1)Binaray\n2)ascii Suggested\n"
op = gets.to_i
print "File to send location/name\n"
from = gets.strip
print "Place to save file\n"
to = gets.strip
if op == 1 then
$ftp.putbinaryfile(from,to)
elsif op == 2 then
$ftp.puttextfile(from,to)
else "If you dont know how to enter a 1 or 2 then you dont send
the file\n"
end
print "\n",$ftp.lastresp,"\n"
end
def others
end
man
$ftp.close
sleep 2
##############code#######

Thank you.
 
T

ts

try with

r> elsif choice==7 then
r> print "Enter new folder name:\n"
r> nwfold = gets

nwfold = gets.chomp # remove \n at the end

r> $ftp.mkdir(nwfold)
r> choice = -1


Guy Decoux
 
R

ruby talk

i did
nwfold = gets.strip
I did it every where else. Why would i not do it for that input? I
dont know. Thank you. What really gets me is that it creates the
folder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top