Mysterious error while uploading files using ftp

Hi guys,

following method of my FTP class will throw out following Exception




yii\base\ErrorException: ftp_put(): Using BINARY mode to transfer data. in 

D:\xampp\htdocs\yii2_perswitch\common\wsl_components\FTPZugang.php:105



Here is method which will 'cause this error





    public function DateienHochloaden($render = NULL, $connection, $localFile, $LocalDirectory) {

        $session = new Session();

        $txt = '/txt/';

        try {

            $basis = $this->GetZugangsDaten($render);

            $SourceDirectory = $basis[4];

            if (preg_match($txt, $localFile))

                $mode = FTP_ASCII;

            else

                $mode = FTP_BINARY;

            try {

                $putFile = $connection->put($SourceDirectory . $localFile, $LocalDirectory . $localFile, $mode);

            } catch (\Exception $e) {

                $SwitchFTP = $this->FTPPassivModus();

                if ($SwitchFTP[0]) {

//This will throw out Exception. So, this is line 105!

                    $putFile = ftp_put($SwitchFTP[1], $SourceDirectory . $localFile, $LocalDirectory . $localFile,$mode);

                    $session->addFlash('info', 'Der Upload erfolgte im Passivmodus. Das deutet auf Probleme mit Ihrer Netzwerkkonfiguration hin. Informieren Sie Ihren Admin<br><br> Einzelheiten hier:' . $e);

                } else {

                    $putFile = false;

                }

            }



This will show var_dump:




var_dump($SwitchFTP[1]);

var_dump($SourceDirectory.$localFile);

var_dump($LocalDirectory.$localFile);

var_dump($mode);

// will show this::


resource(191) of type (FTP Buffer) 

string(20) "/Uploads/ man_2.jpg" 

string(63) "D:\xampp\htdocs\yii2_perswitch\frontend/uploadedfiles/man_2.jpg" 

int(2) 



As it seems, ft_put is wrong implemented. I have absolutely no idea, why!?

I used to implement this code according to php manuals. Nevertheless, I will get upper Exception

Any ideas, what I do wrong?

I guess your parameters are wrong.

Check also directory, filename, space, \ and /

U are right. Connection string in database was wrong. So, it created following output(look at my publishing above)




var_dump($SourceDirectory.$localFile);  <=>  string(20) "/Uploads/ man_2.jpg" 



There is space between backslash and filename. This was causing error. After having put right string into database,

transfer was well done in Active mode.

This thread can be closed as succesfully solved