PDA

View Full Version : Link to files in Anon FTP?


kerim
04-17-2001, 05:14 AM
This page on my site has links to files in my Anonymous FTP folder:

http://kerim.oxus.net/documents.html

But the links don't work. I always get "file not found" problems. This is true even though if I go through my FTP hierarchy manually from inside an FTP program I get the file without problems. In fact, the URLs were created by copying the URL from my FTP program. But something is wrong. Any help would be *greatly* appreciated. (It seems that about 99% of my problems with coding are all to do with properly locating the path to files!)

Here is an example URL:

ftp://anonymous@oxus.net/public_ftp/kerim/Documents/Syllabi/World_Cultures.pdf

Below is a transcript of both failed (from the web page) and successful (manual) FTP logs:

(1) Failed:

220 ProFTPD 1.2.0 Server (ProFTPD) [host7.hrwebservices.net]
USER anonymous
331 Anonymous login ok, send your complete email address as your password.
PASS *****
230 Anonymous access granted, restrictions apply.
PWD
257 "/" is current directory.
MACB E
500 MACB not understood.
TYPE I
200 Type set to I.
SIZE /public_ftp/kerim/Documents/Research/Proposal.PDF
550 /public_ftp/kerim/Documents/Research/Proposal.PDF: No such file or directory
PASV
227 Entering Passive Mode (216,74,100,93,6,119).
RETR /public_ftp/kerim/Documents/Research/Proposal.PDF
550 /public_ftp/kerim/Documents/Research/Proposal.PDF: No such file or directory
QUIT

(2) Successful

220 ProFTPD 1.2.0 Server (ProFTPD) [host7.hrwebservices.net]
USER *****
331 Password required for ******.
PASS *****
230 User ****** logged in.
PWD
257 "/" is current directory.
MACB E
500 MACB not understood.
TYPE I
200 Type set to I.
SIZE /public_ftp/kerim/Documents/Research/Proposal.PDF
213 69669
PASV
227 Entering Passive Mode (216,74,100,93,6,140).
RETR /public_ftp/kerim/Documents/Research/Proposal.PDF
150 Opening BINARY mode data connection for /public_ftp/kerim/Documents/Research/Proposal.PDF (69669 bytes).
QUIT
226 Transfer complete.

Note: The path seems to be *exactly the same* in the two transcripts! I am very confused.

I posted these transcripts to tech support and they simply told me to log in as "anonymous" rather than no user. I changed the URL accordingly (as listed above) but still no go . . .

kerim

DCE
04-17-2001, 06:48 AM
Kerim,

Just a thought that could be way out... I'm sure someone will correct me

Wouldn't the link be... ftp://anonymous:anonymous@oxus.net/pub/Cultures.pdf

I tried it but I don't think you've got "Cultures.pdf" in your "pub" folder... at least I couldn't find it when I looked with WS_FTP

eric418
04-27-2001, 10:51 PM
Because this is a virtual hosting.

you should use "anonymous@domain.com" as the login for anonymous FTPing.

if you use "anonymous" as the login, it actually pointing to the server's anonymous directory which is NOT ur own FTP directory.

Just use anonymous@domain.com as the login will solve your problem.

eric418
04-27-2001, 10:54 PM
Forgot sth.

you have to use "anonymous" as the password too i guess.

loveofcolor
08-14-2001, 11:35 PM
Here is your answer:

Unfortunatly, you can't use FTP urls on host rocket pages.

Here is how normal FTP URLs work:
ftp://username:login@domain.com:port/directory .

Notice how there is only one @ symbol?

The way HostRocket anonymous FTP is set up, the Username and has an @ symbol in it also, which causes problems when you use it in a URL, such as:
ftp://anonymous@oxus.net:anonymous@oxus.net/file.pdf .

That link won't work because there are two @ symbols.
You should get a "Incorrect Syntax" error.


The best thing to do is to tell people to just go to ftp.oxus.net and then login as:
user: anonymous@oxus.net
pass: anonymous

did that help?

kerim
08-14-2001, 11:42 PM
Thanks for all the help. I finally decided to not use FTP, but to use a PHP/SQL combination to initiate downloads. This seems to work very well, and I'm not having any problems. I even get a log of who downloaded what when. - kerim

boncor
08-15-2001, 05:30 AM
cmon! don't leave us hangin.

I am sure others (as well as me) would like to hear where you got the script, etc.

do you have a link?

kerim
08-15-2001, 11:16 AM
OK, here is my highly edited version of the script. There is a link to the origional script at the top. My version doesn't keep a databaseof the IP and time, but it does e-mail this information. Also, the origional doesn't keep the filename information in a database. Mine does -I find it helps to get the correct filename on download. Don't distribute the script without opening the origional script and looking at the actual license. -kerim

<?PHP

// This script is an adaptation of Download Manger
// which can be seen at (www.tunga.com/PHP)
// See Tunga.com script for origional license.

include("downlogin.php");

// You'll have to set up a SQL databse with a table called "filelist" and the following items: id, filename, num.

$filelist = mysql_query(
"SELECT * FROM files WHERE id='$id'");

while ($row = mysql_fetch_array($filelist)) {
$id = $row["id"];
$filename = $row["filename"];
$num = $row["num"];

// sends them the PDF file

$file_location = "/home/username/public_html/***/"; // edit to your folder settings


$file_path = $file_location . $filename;
if (detect_browser($HTTP_USER_AGENT) == "ie")
{
Header("Content-type: application/force-download");
}else{
Header("Content-Type: application/octet-stream");
}
Header("Content-Length: ".filesize($file_path));
Header("Content-Disposition: attachment; filename=$filename");
readfile($file_path);

// add 1 to number of downloads

$sql = mysql_query(
"UPDATE files SET num = num + 1 WHERE id='$id'") or DIE(mysql_error());

// Find the real ip adress and host of downloader

if (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip = getenv('HTTP_X_FORWARDED_FOR');
}else {
$ip = getenv('REMOTE_ADDR');
}
$host = isset($REMOTE_HOST) ? $REMOTE_HOST : @gethostbyaddr($ip);

// Today's date on 2001-05-22 18:15:16 format
$thedate = date("Y-m-d H:i:s");

//Total downloads
$downloads = $num + 1;

// Send E-mail Notification
$recipient = "username@domain.com"; // Edit to your address
$subject = "PHP Download Notification";
$headers .= "From: PHP Dowload script <webmaster@domain.com>\n"; // You can set this however you like

// message body
$message .= "The file *** '$filename' *** was just downloaded.\r\n";
$message .= "Today '$thedate' \r\n";
$message .= "To the following host: '$host' \r\n";
$message .= "It has been downloaded '$downloads' times so far.\r\n";

/* and now mail it */
mail($recipient, $subject, $message, $headers) or DIE(mysql_error());;

}

// this is the function called to determine the browser

function detect_browser($variable)
{
if(eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})", $variable))
{
$content = "ie";
}else{
$content = "nn";
}
return $content;
}


?>