Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP Script from an HTML Page ...

Status
Not open for further replies.

MojoZig

Technical User
Sep 27, 2005
61
US
Why doesn't this work? I can use the user name/password/ftp server in the browser window and it works, but it seems that this script isn't putting everything where it needs to go... Thoughts?

This is the script in the HEAD tag ...


Code:
<SCRIPT LANGUAGE="JavaScript">


<!-- Begin
function Login(form) {
var username = form.username.value;
var password = form.password.value;
var server = form.server.value;
if (username && password && server) {
var ftpsite = "ftp://" + username + ":" + password + "@" + server;
window.location = ftpsite;
}
else {
alert("Please enter your username, password, and FTP server's address.");
   }
}
//  End -->
</script>



This is the code in the body ...

Code:
<center>
<form action="post" name=login>
<table width=250 border=0 cellpadding=3>
<tr>
<td colspan=2 align=center><b><h2>Logon to FTP Server!</h2></b></td>
</tr>
<tr>
<td>Username:</td>
<td><input type=text name=username size=20></td>
</tr>
<tr>
<td>Password:</td>
<td><input type=password name=password size=20></td>
</tr>
<tr>
<td>Server:</td>
<td><tt>ftp://</tt><input name=server type=text size=14></td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=button value="Login!" onClick="Login(this.form)"></td>
</tr>
</table>
</form>
</center>
 
I think it was the password for my user account ... it has a $, !, and a ? in the password ... It must break the script ...

I tried it with another user name and password and it works but it takes you to an html page at the root of the server when using the login and password usually takes you directly to the users directory ...

If anybody has any ideas, I'd appreciate it ... but I might just have a link to the ftp server and let it's login box do the work ...

TT
 
Ok, I think the problem is:

Code:
var ftpsite = "ftp://" + username + ":" + password + "@" + server;
window.location = ftpsite;

When I use the: ftp://username:password@server IE takes you right to the folder that the user is assigned ...

When the script does it, it takes the user to an html page that list the root of the ftp server folders ...

Can I change the window.location to something else that may make ie open the correct folder?

TT
 
It works for me here.

Make certain you are not getting an earlier cached version of your page when you test changes. Flush the cache.
Always do a Shift-Refresh to reload the page, then test.



Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top