Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    Error: can not change working directory

    I keep getting the error: "Cannot change working directory. No such file or directory"?

    My FTP log in information will lead to the 'public_ftp' folder.

    I created a directory inside 'public_ftp' as '/uploads/aa', and the permission is 777. So in terms of ftp->cwd(''), how should I write the path to my folder? Should it be:
    1) ' ../uploads/aa',
    2) '/uploads/aa', or
    3) '/home/mysitecom/domains/mysite.com/public_ftp/uploads/aa'?
    I tried them all, and none of them are working?

    Code:
    use Net::FTP; 
    
    mkdir("../uploads/aa", 0777);
    
    my $ftp = Net::FTP->new("host.com") 
    or die "Cannot connect to the host";
    
    $ftp->login('user',"password")
    or die "Cannot login ", $ftp->message; 
    
    $ftp->cwd('/uploads/aa') or die "Cannot change working directory ", $ftp->message;
    
    $ftp->put($upload_file, $upload_file) 
    or die "get failed ", $ftp->message;
     
    $ftp->quit;
    Last edited by camaross; 04-10-2011 at 05:37 AM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    filesystem path and ftp, http are distinct. one way to fix your problem is to see where you are when you open the ftp connection and start from there to build the path.
    for example if $ftp->cwd('/') is /home/mysitecom/domains/mysite.com/public_ftp/
    then the path to /home/mysitecom/domains/mysite.com/public_ftp/uploads/aa will be $ftp->cwd('/uploads/aa/')

    Edit: the ftp user need to have access to the directory, not only permission, check the owner, user must be the owner or in the same group with the owner

    best regards
    Last edited by oesxyl; 04-10-2011 at 06:52 AM.

  • Users who have thanked oesxyl for this post:

    camaross (04-10-2011)

  • #3
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you, Man!

    Quote Originally Posted by oesxyl View Post
    filesystem path and ftp, http are distinct. one way to fix your problem is to see where you are when you open the ftp connection and start from there to build the path.
    for example if $ftp->cwd('/') is /home/mysitecom/domains/mysite.com/public_ftp/
    then the path to /home/mysitecom/domains/mysite.com/public_ftp/uploads/aa will be $ftp->cwd('/uploads/aa/')

    Edit: the ftp user need to have access to the directory, not only permission, check the owner, user must be the owner or in the same group with the owner

    best regards

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    Thank you, Man!
    i seen this now:
    Code:
    mkdir("../uploads/aa", 0777);
    1. you create the dir '../uploads/aa' on your local machine not remote,
    2. if you run the script in /home/mysitecom/domains/mysite.com/public_ftp/ this command will create /home/mysitecom/domains/mysite.com/uploads/aa, this in case it work, because usualy for security reasons you can't use ..

    best regards

  • Users who have thanked oesxyl for this post:

    camaross (04-10-2011)

  • #5
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Genius!!!

    Now I fixed the problem by doing the mkdir after logging into ftp and use '$ftp->mkdir' instead.

    Thank you!

    Quote Originally Posted by oesxyl View Post
    i seen this now:
    Code:
    mkdir("../uploads/aa", 0777);
    1. you create the dir '../uploads/aa' on your local machine not remote,
    2. if you run the script in /home/mysitecom/domains/mysite.com/public_ftp/ this command will create /home/mysitecom/domains/mysite.com/uploads/aa, this in case it work, because usualy for security reasons you can't use ..

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •