Welcome Guest, Not a member yet? Register   Sign In
CI FTP Library- unable to create folder
#1

[eluser]hackersapien[/eluser]
I've been using the CI FTP library for a webapp I'm doing. In the app I'm supposed to connect to a server, create a folder in a specific directory, and then copy files from one directory to the next. Using the FTP Library I can connect to the server but I cannot create a folder, it's not a rights issue since using the same FTP credentials I can create folders easily. Has anybody experienced the same problem?
#2

[eluser]Christoffer[/eluser]
I have recently done a lot of work in the FTP-class. Both the native functions and my own extensions. Can you show me your code and print the value of all variables?

E.g. when I ran into a problem of this kind I usually do something like:

Code:
echo "Trying to recreate $locpath at $rempath.";

This way you can often see what the problem is. Also, a problem with the mirror function is that you're not able to set file permissions unless you extend the library yourself.

Do you run a Windows server or Linux server?

/Christoffer
#3

[eluser]hackersapien[/eluser]
This is my code:
Code:
if ($this->ftp->connect($config)) {
                if($this->ftp->mkdir($r->dest_ftp_path.'/2008/January/',0777)){
                    $this->data['success'] = "Folder created";
                }else{
                    $this->data['errors']= "error";
                }
                
                
            }

I'm not using the mirror() function in the FTP class, i'm using the mkdir() function. I preferred to test the folder creation before moving to the copying or moving of files. In the next phase of my webapp I'm supposed to connect to a second FTP server, create a directory structure like <Year>/<month> in the destination directory and copy files from source FTP server to destination FTP server.

I have confirmed that the FTP class connects to the server so no issues there.

When I echo
Code:
$r->dest_ftp_path
it shows me the correct destination path, which in this case is /dbbackup/dl
#4

[eluser]hackersapien[/eluser]
it seems the method for creating a directory doesn't allow you to create multiple sub-directories like "/2008/January" means I have to create them one by one, so now this is what I have:
Code:
if ($this->ftp->connect($config)) {
                if($this->ftp->mkdir($r->dest_ftp_path.$dir_year,0777)){
                    if($this->ftp->mkdir($r->dest_ftp_path.$dir_year.$dir_month,0777)){
                        $new_path=$r->dest_ftp_path.$dir_year.$dir_month;
                        $this->data['success'] = "successfully created sub-directories $new_path";
                    }
                }
            }

Not the cleanest code I must admit, have u dealt with creation of sub-folders?
#5

[eluser]Christoffer[/eluser]
Yes I have. It is a pain but everything needs to be created in the correct order.

What you can do if you don't have full control of what is being created is to extend the FTP class and the mkdir function so that if it's not able to create the new dir, it splits the path on '/' into an array.

Thereafter you can check each dir recursively and if it exists. If not, attempt to create it.
#6

[eluser]hackersapien[/eluser]
I'd also like to COPY not MOVE the files, currently there's no method to do that in the FTP class
#7

[eluser]Christoffer[/eluser]
There's no function for that in the PHP docs either. You'll have to write it yourself.

http://se2.php.net/manual/en/function.ftp-put.php
http://se2.php.net/manual/en/function.ftp-fput.php
http://se2.php.net/manual/en/function.ftp-get.php
http://se2.php.net/manual/en/function.ftp-fget.php

Check out the docs for those functions and you should come up with a solution. This is how I would do it:

1. Download the file to your local harddrive.
2. Upload the downloaded file to the FTP again, in the dir you want to copy to.
3. Remove the file from your local harddrive using the unlink() method.

Good luck and let me know if you run in to any problems.




Theme © iAndrew 2016 - Forum software by © MyBB