Jump to content

FTP Get


Asheeown

Recommended Posts

I'm trying to download everything from a directory using the script below, but it just the IF statement keeps coming up false, take a look

 

$LocalDirectory = $LocalDirectory . $Type;
$FtpConnect = ftp_connect($Server);
$Login = ftp_login($FtpConnect, $Username, $Password);

ftp_chdir($FtpConnect, $Directory);
echo ftp_pwd($FtpConnect);
echo "</br>";
$array = ftp_rawlist($FtpConnect, '/CDR');
$Files = GetFiles($array);
ftp_close($FtpConnect);


function GetFiles( $array ) {

   for ( $i = 1; $i < count($array); $i++ ) {

       $current = $array[$i];
  
       $structure[$i]['perms']  = substr($current, 0, 10);
       $structure[$i]['number'] = trim(substr($current, 11, 3));
       $structure[$i]['owner']  = trim(substr($current, 15, );
       $structure[$i]['group']  = trim(substr($current, 24, );
       $structure[$i]['size']  = trim(substr($current, 33, );
       $structure[$i]['month']  = trim(substr($current, 42, 3));
       $structure[$i]['day']    = trim(substr($current, 46, 2));
       $structure[$i]['time']  = substr($current, 49, 5);
       $structure[$i]['name']  = substr($current, 55, strlen($current) - 55);

   }

   return $structure;

}
echo "<br><br>";
foreach($Files as $f) {
$Remote = $f[name];
$Local = "CDRS/Raw/$f[name]";

if (ftp_get($FtpConnect, $Local, $Remote, FTP_BINARY)) {
   echo "Successfully written to $Local\n";
} else {
   echo "There was a problem\n";
}
}

 

The FTP connection is successful everything is fine till the get statement

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/
Share on other sites

$LocalDirectory = $LocalDirectory . $Type;
$FtpConnect = ftp_connect($Server);
$Login = ftp_login($FtpConnect, $Username, $Password);

ftp_chdir($FtpConnect, $Directory);
echo ftp_pwd($FtpConnect);
$Files = ftp_nlist($FtpConnect, ".");

foreach($Files as $f) {
$Remote = $f;
$Local = "CDRS/Raw/$f";
if (ftp_get($FtpConnect, $Local, $Remote, FTP_BINARY)) {
   echo "Successfully written to $Local\n";
} else {
   echo "There was a problem\n";
}
}
ftp_close($FtpConnect);

 

Sure it's more organized now but it still doesn't download any files

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187293
Share on other sites

i dont man it says

 

local_file

The local file path (will be overwritten if the file already exists).

 

 

also well ftp_fget  function exists too

 

 

ftp_fget -- Downloads a file from the FTP server and saves to an open file

ftp_fget() retrieves remote_file from the FTP server, and writes it to the given file pointer.

 

so if its a pointer you can assign it to  fopen()  php functions and save it to whatever path you want and check if it exists and other stuff

 

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187347
Share on other sites

Well I think that $local thing is just the filename of the local want you want to rename the file

 

the files should all save around the php script it self  if you make $local = f;

 

I think the true why to set the paths would be to fiddle with the php.ini ftp saving paths etc... if you cant access them use ini_set()

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187536
Share on other sites

$LocalDirectory = $LocalDirectory . $Type;
$FtpConnect = ftp_connect($Server);
$Login = ftp_login($FtpConnect, $Username, $Password);

ftp_chdir($FtpConnect, $Directory);
echo ftp_pwd($FtpConnect);
$Files = ftp_nlist($FtpConnect, ".");
ftp_chdir($FtpConnect,"/");
foreach($Files as $f) {
$Remote = "/$Directory/$f";
$Local = "$f";
echo "File: $Remote is being written as $Local<br>";
if(ftp_fget($FtpConnect, $Local, $Remote, FTP_BINARY)) {
	echo "File: $Remote was downloaded successfully";
} else {
	echo "File: $Remote was not downloaded";
}

}
ftp_close($FtpConnect);

 

The file path is now /CDR/"file", which is the exact path that it should be and still nothing

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187556
Share on other sites

confused it doesn't go up to line 27 and   that link you posted is just listing files as

 

 

File: blah.cdr is being written as blah.cdr

File: blah.cdr was not downloaded

 

 

maybe change FTP_BINARY To  FTP_ASCII

 

 

ok i see the not downloaded part is related to

 

ftp_fget($FtpConnect, $Local, $Remote, FTP_BINARY

 

its all that thats messed up  I dont know I see no error there  maybe on remote

 

$Remote  replace to  '$Remote'  on the ftp_fget line

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187574
Share on other sites

In my script it registers all the variables thats what the extra lines are but thats mostly FTP information thats not needed here

 

 

FTP_ASCII doesn't work either, this is quite confusing, is their a log file or anything that I can look through, this is my server I can absolutely anything on

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187577
Share on other sites

well  try

 

ftp_fget($FtpConnect, $Local, '$Remote', FTP_BINARY) 

 

with quotes   I seen that off a php.net site a hour ago

 

Confusing yes.. try some simple scripts that are proven to work maybe its a bad php configuration

 

Example 360. Download a file and write it out 

$ftpStream = ftp_connect('my.ftp.server');
$loginResult = ftp_login($ftpStream, 'username', 'password');
if ($loginResult) {
            //local file location is in the same directory as the PHP file
            $destination = 'local.txt.';

            //open a file pointer for writing in the same directory as the PHP file
   $fp = fopen($destination, 'w');

            //retrieve the file from the FTP server and write it to the file pointer 
   ftp_fget($ftpStream, $fp, 'remote.txt', FTP_ASCII);
            
            //close the file stream
            fclose($fp);

            //print out the contents of the file to the screen and close the file
            $fp = fopen($destination, 'r');
   fpassthru($fp);
}
ftp_quit($ftpStream);

Link to comment
https://forums.phpfreaks.com/topic/38817-ftp-get/#findComment-187581
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.