当前位置:软件学堂 > 资讯首页 > 网络编程 > 编程其他 > JS实现FTP网站登录

JS实现FTP网站登录

2012/11/14 14:37:52作者:佚名来源:网络

移动端

【实例名称】

JS实现FTP网站登录

【实例描述】

FTP是文件传输协议,一般用于往服务器上传送文件。本例简单制作了一个FTP网站的登录界面。

【实例代码】

<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>标题页-学无忧(www.xue51.com)</title> <script janguage="javascript"> function goFtpSite() {  //当前页面的导航,注意登录地址、用户名和密码 document.location.href = "ftp://" + document.ftp.login.value + ":" + document.ftp.password.value + "@" + document.ftp.url.value; } </script> </head> <body> <form name="ftp"> <table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" align="center"> <tr> <td> <table border="0" cellspacing=0 cellpadding=5 align="center"> <tr bgcolor="#bbbbbb"> <td width="75" align="right"> <font face="arial,helvetica" size="-1"> Ftp:// </font> </td> <td> <font face="arial,helvetica" size="-1"> <input type="text" size=15 name="url"> </font> </td> </tr> <tr bgcolor="#dddddd"> <td align="right"> <font face="arial,helvetica" size="-1"> Login: </font> </td> <td> <font face="arial,helvetica" size="-1"> <input type="text" size="15" name="login" maxlength="20"> </font> </td> </tr> <tr bgcolor="#bbbbbb"> <td align="right"> <font face="arial,helvetica" size="-1"> Password: </font> </td> <td> <font face="arial,helvetica" size="-1"> <input type="password" size="15" name="password" maxlength="20"> </font></td> </tr> <tr bgcolor="#ffffff"> <td colspan="2" align="center"> <font face="arial,helvetica" size="-2"> <input type=button onclick="goFtpSite();" value="登录"> <input type=reset value="清空"> </font> </td> </tr> </table> </td> </tr> </table> </form> </body> </html>

【运行效果】

 FTP网站登录运行效果

【难点剖析】

本例的重点其实是传输协议的设置。如果要定位到普通网站,则“document.location.href”属性要设置为以“http://”开头。如果要定位到FTP网站则需要以“ftp://”开头,并且指定登录名和登录密码。

【源码下载】

为了JS代码的准确性,请点击:FTP网站登录 进行本实例源码下载