File selection for ftp download.

well now you know why this does not work

[php]
“<a href=upgrades/$workingDir/” . $fList[$i] . “>”
[/php]

where have i gone wrong?

Okay, I understand your question better now…

So, your line: $workingDir = ftp_pwd($conn); just gets the current directory (folder) you are currently in.
But, you must set the directory you want to be in. The FTP log-in does NOT set the directory for you.

So, let’s recap this process…

Your current code creates a FTP connection, logs into the connection and then reads the current directory from the connection. Therefore, it will always be in the root folder which is always “” or null. So, as-is your code is doing exactly what you asked of it.

Now, what you should be doing is create a FTP connection, log into the connection and then set the directory (folder) to the folder where your files are, in this case “upgrades”.

So, instead of reading the connection’s current directory, set it to the upgrades folder. Something like this:
ftp_chdir($conn, ‘upgrades’);
After that command, the FTP connection will point at the files and you can pull the list from there.

Hope that helped…

That doesn’t work either :’(
The ‘upgrades’ folder is the parent folder and the final folder will vary depending on the login credentials like so:

upgrades/psu/ or upgrades/mike/ or upgrades/ups/ etc.

The code i have upto now must be getting the correct folder info as it will display the files in the folders,
but when i select it for download the file path is ‘upgrades//’ then the file name when it should be
upgrades/psu/ or upgrades/mike/ or upgrades/ups/ then filename.

[php]$conn = @ftp_connect($ftpServer)
or die(“Couldn’t connect to FTP server”);

$login = @ftp_login($conn,$ftpUser,$ftpPass)
or die(“Login credentials were rejected”);
$workingDir = ftp_pwd($conn);
$fList = @ftp_nlist($conn, $workingDir);
if(is_array($fList))
{
for($i = 0; $i < sizeof($fList); $i++)
{
echo “’<a href=upgrades/$workingDir’” . $fList[$i] . “>” . $fList[$i] . “
”;
}
}
else
{
echo “$workingDir contains no files.”;
}

?> [/php]

Okay, I will repeat…

Your code: $workingDir = ftp_pwd($conn); Sets the variable $workingDir to the ROOT directory of the FTP connection. This will NEVER work for you because you NEVER set the directory of the FTP connection. So you are trying to use a NULL as the variable $workingDir. (As I said before!)

You must SET the directory of the FTP to whatever you want to use. Therefore, if you are using the user’s login info as the folder/directory you want to start at in the FTP connection, YOU have to set that before you can assign it to the variable $workingDir.
Something like: ftp_chdir($conn, ‘upgrades/Mike’); or ftp_chdir($conn, ‘upgrades/ups’); or…

So, if you are using the variable “$ftpUser” for the login credentials and IF that is the folder name, use it
something like this: ftp_chdir($conn, ‘upgrades/$ftpUser’); This will set you to the correct folder. And,
then, when you pull the current folder into your $workingDir variable, it will get the correct value.
But, since you are also using a different variable in your version of your code, you could just change it
to something like this: $workingDir = “upgrades/” . $ftpUser; This would bypass the setting of the folder.

Hope you understand this now. Let us know if you do not…

It works ok now.
I changed ‘$workingDir’ to ‘$ftpUser’ and renamed the ftp server directory’s to the user names.

[php]echo “<a href=upgrades/$ftpUser” . $fList[$i] . “>” . $fList[$i] . “
”;[/php]

I wouldn’t have got this far without all your help, so thanks very much.

Great! Congrats! Always a warm fuzzy feeling to solve a code puzzle… Glad we could help!

See you again in the bitstream… (All that this really is, LOL)

Sponsor our Newsletter | Privacy Policy | Terms of Service