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
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
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
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
Share on other sites

im just saying maybe $local is just a filename not path  like the old windows ftp.exe program you would just specify the file you wanted to download and the filename you wanted to rename it to IF you wanted to rename it that is.. it would download to desktop

Link to comment
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
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
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
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
Share on other sites

than it has to be a php.ini problem says here on a FTP readme for some script that

 

allow large file uploads and transfers, you may have to change these settings:

in the file php.ini (directory C:\windows or /etc): upload_max_filesize, post_max_size, max_execution_time, memory_limit

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.