# Trouble with Dir.chdir

**URL:** <https://www.ruby-forum.com/t/trouble-with-dir-chdir/94768>\
**Category:** Rails\
**Created:** [May 13, 2006, 3:14pm UTC](https://www.ruby-forum.com/t/trouble-with-dir-chdir/94768 "2006-05-13T15:14:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 13, 2006, 3:14pm UTC](https://www.ruby-forum.com/t/trouble-with-dir-chdir/94768/1 "2006-05-13T15:14:12Z")

</div>

Hi, folks

I wroted the codes below.

I have the trouble with the line start from “Dir.chdir”.

When I run this code, the FTP of photos is successfuly done.  
But, the display of browser is white out.

When I comment out the line start from “Dir.chdir”,  
the trouble doesn’t happen.

Is there anything wrong with my usage of “Dir.chdir”?

def ftp\_photo  
$basedir = “/home/yosuke/public\_html/myalbum/albums/”  
$tempdir = “/home/yosuke/public\_html/testing/tempPhoto/”

targetdir = params[:targetdir]  
@targetdir = params[:targetdir]

fhostname = ‘hogefpt.co.jp’  
fusername = ‘hoge’  
fuserpass = ‘hogehoge’  
fbasedir = ‘/hogehoge/’

targetdirpath = $tempdir + targetdir  
Dir.chdir targetdirpath

begin  
ftp = Net::FTP.open(fhostname,fusername,fuserpass)  
@messageftpconnect = “connected”  
rescue  
@messageftpconnect = “failed”  
end

ftp.chdir(fbasedir)

begin  
ftp.mkdir(targetdir)  
@messageftpmkdir = “the directory was created”  
rescue  
@messageftpmkdir = “the directory already exists”  
end

ftp.chdir(targetdir)

Dir::glob(“./\*.jpg”).each {|f|  
ftp.put(f)  
}

ftp.close

FileUtils.rm\_rf(targetdirpath)

end

ftp\_photo.rhtml

start e$B#F#T#Pe(B

\<%= @messageftpconnect %\>

\<%= @messageftpmkdir %\>

layout file

 my tool \<%= stylesheet\_link\_tag "mytool", :media =\> "all" %\> 
 my tools 

[home](http://www)  

 \<% if @flash[:notice] -%\> 
\<%= @flash[:notice] %\>
 \<% end %\> \<%= @content\_for\_layout %\> 

#Sorry japanese readers,  
#I sent the same mail to the ML for japanese rails users

* * *

Yosuke Suzuki from Japan
