當前位置:首頁 » 文件管理 » asp實現ftp

asp實現ftp

發布時間: 2022-06-30 05:42:48

⑴ ASP.net 實現打開伺服器ftp文件夾

給你一個訪問ftp類。傳入用戶密碼等,直接調用裡面方法就可以了。能實現文件下載等
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;

namespace JySoft.SaleFrame.Facade
{
/// <summary>
/// FTP 的摘要說明。
/// </summary>
public class FTPServer
{
private string strRemoteHost;
private int strRemotePort;
private string strRemotePath;
private string strRemoteUser;
private string strRemotePass;
private Boolean bConnected;

#region 內部變數
/// <summary>
/// 伺服器返回的應答信息(包含應答碼)
/// </summary>
private string strMsg;
/// <summary>
/// 伺服器返回的應答信息(包含應答碼)
/// </summary>
private string strReply;
/// <summary>
/// 伺服器返回的應答碼
/// </summary>
private int iReplyCode;
/// <summary>
/// 進行控制連接的socket
/// </summary>
private Socket socketControl;
/// <summary>
/// 傳輸模式
/// </summary>
private TransferType trType;
/// <summary>
/// 傳輸模式:二進制類型、ASCII類型

/// </summary>
public enum TransferType
{
/// <summary>
/// Binary
/// </summary>
Binary,
/// <summary>
/// ASCII
/// </summary>
ASCII
};
/// <summary>
/// 接收和發送數據的緩沖區
/// </summary>
private static int BLOCK_SIZE = 512;
Byte[] buffer = new Byte[ BLOCK_SIZE];
/// <summary>
/// 編碼方式
/// </summary>
Encoding ASCII = Encoding.Default;
#endregion

#region 內部函數

#region 構造函數
/// <summary>
/// 預設構造函數
/// </summary>
public FTPServer()
{
strRemoteHost = "";
strRemotePath = "";
strRemoteUser = "";
strRemotePass = "";
strRemotePort = 21;
bConnected = false;
}

/// <summary>
/// 構造函數
/// </summary>
/// <param name="remoteHost"></param>
/// <param name="remotePath"></param>
/// <param name="remoteUser"></param>
/// <param name="remotePass"></param>
/// <param name="remotePort"></param>
public FTPServer( string remoteHost, string remotePath, string remoteUser, string remotePass, int remotePort )
{
strRemoteHost = remoteHost;
strRemotePath = remotePath;
strRemoteUser = remoteUser;
strRemotePass = remotePass;

strRemotePort = remotePort;
Connect();
}
#endregion

#region 登陸
/// <summary>
/// FTP伺服器IP地址
/// </summary>

public string RemoteHost
{
get
{
return strRemoteHost;
}
set
{
strRemoteHost = value;
}
}
/// <summary>
/// FTP伺服器埠
/// </summary>
public int RemotePort
{
get
{
return strRemotePort;
}
set
{
strRemotePort = value;
}
}
/// <summary>
/// 當前伺服器目錄
/// </summary>
public string RemotePath
{
get
{
return strRemotePath;
}
set
{
strRemotePath = value;
}
}
/// <summary>
/// 登錄用戶賬號
/// </summary>
public string RemoteUser
{
set
{
strRemoteUser = value;
}
}
/// <summary>
/// 用戶登錄密碼
/// </summary>
public string RemotePass
{
set
{
strRemotePass = value;
}
}

/// <summary>
/// 是否登錄
/// </summary>
public bool Connected
{
get
{
return bConnected;
}
}
#endregion

#region 鏈接
/// <summary>
/// 建立連接
/// </summary>
public void Connect()
{
socketControl = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(RemoteHost), strRemotePort);
// 鏈接
try
{
socketControl.Connect(ep);
}
catch(Exception)
{
throw new IOException("連接不上FTP伺服器!");
}

// 獲取應答碼
ReadReply();
if(iReplyCode != 220)
{
DisConnect();
throw new IOException(strReply.Substring(4));
}

try
{
// 登陸
SendCommand("USER "+strRemoteUser);
if( !(iReplyCode == 331 || iReplyCode == 230) )
{
CloseSocketConnect();//關閉連接
throw new IOException(strReply.Substring(4));
}
if( iReplyCode != 230 )
{
SendCommand("PASS "+strRemotePass);
if( !(iReplyCode == 230 || iReplyCode == 202) )
{
CloseSocketConnect();//關閉連接
throw new IOException(strReply.Substring(4));
}
}
}
catch
{
throw new IOException("登錄用戶名密碼錯誤!");
}
bConnected = true;

// 切換到目錄
ChDir(strRemotePath);
}

/// <summary>
/// 關閉連接
/// </summary>
public void DisConnect()
{
if( socketControl != null )
{
SendCommand("QUIT");
}
CloseSocketConnect();
}

#endregion

#region 傳輸模式

/// <summary>
/// 設置傳輸模式
/// </summary>
/// <param name="ttType">傳輸模式</param>
public void SetTransferType(TransferType ttType)
{
if(ttType == TransferType.Binary)
{
SendCommand("TYPE I");//binary類型傳輸
}
else
{
SendCommand("TYPE A");//ASCII類型傳輸
}
if (iReplyCode != 200)
{
throw new IOException(strReply.Substring(4));
}
else
{
trType = ttType;
}
}

/// <summary>
/// 獲得傳輸模式
/// </summary>
/// <returns>傳輸模式</returns>
public TransferType GetTransferType()
{
return trType;
}

#endregion

#region 文件操作
/// <summary>
/// 獲得文件列表
/// </summary>
/// <param name="strMask">文件名的匹配字元串</param>
/// <returns></returns>
public string[] Dir(string strMask)
{
// 建立鏈接
if(!bConnected)
{
Connect();
}

//建立進行數據連接的socket
Socket socketData = CreateDataSocket();

//傳送命令
SendCommand("NLST " + strMask);

//分析應答代碼
if(!(iReplyCode == 150 || iReplyCode == 125 || iReplyCode == 226))
{
return null;
}

//獲得結果
strMsg = "";
while(true)
{
int iBytes = socketData.Receive(buffer, buffer.Length, 0);
strMsg += ASCII.GetString(buffer, 0, iBytes);
if(iBytes < buffer.Length)
{
break;
}
}
char[] seperator = {'\n'};
string[] strsFileList = strMsg.Split(seperator);
socketData.Close();//數據socket關閉時也會有返回碼
if(iReplyCode != 226)
{
ReadReply();
if(iReplyCode != 226)
{
throw new IOException(strReply.Substring(4));

}
}
return strsFileList;
}

/// <summary>
/// 獲取文件大小
/// </summary>
/// <param name="strFileName">文件名</param>
/// <returns>文件大小</returns>
private long GetFileSize(string strFileName)
{
if(!bConnected)
{
Connect();
}
SendCommand("SIZE " + Path.GetFileName(strFileName));
long lSize=0;
if(iReplyCode == 213)
{
lSize = Int64.Parse(strReply.Substring(4));
}
else
{
throw new IOException(strReply.Substring(4));
}
return lSize;
}

/// <summary>
/// 刪除
/// </summary>
/// <param name="strFileName">待刪除文件名</param>
public void Delete(string strFileName)
{
if(!bConnected)
{
Connect();
}
SendCommand("DELE "+strFileName);
if(iReplyCode != 250)
{
throw new IOException(strReply.Substring(4));
}
}

/// <summary>
/// 重命名(如果新文件名與已有文件重名,將覆蓋已有文件)
/// </summary>
/// <param name="strOldFileName">舊文件名</param>
/// <param name="strNewFileName">新文件名</param>
public void Rename(string strOldFileName,string strNewFileName)
{
if(!bConnected)
{
Connect();
}
SendCommand("RNFR "+strOldFileName);
if(iReplyCode != 350)
{
throw new IOException(strReply.Substring(4));
}
// 如果新文件名與原有文件重名,將覆蓋原有文件
SendCommand("RNTO "+strNewFileName);

if(iReplyCode != 250)
{
throw new IOException(strReply.Substring(4));
}
}
#endregion

#region 上傳和下載
/// <summary>
/// 下載一批文件
/// </summary>
/// <param name="strFileNameMask">文件名的匹配字元串</param>
/// <param name="strFolder">本地目錄(不得以\結束)</param>
public void Get(string strFileNameMask,string strFolder)
{
if(!bConnected)
{
Connect();
}
string[] strFiles = Dir(strFileNameMask);
foreach(string strFile in strFiles)
{
if(!strFile.Equals(""))//一般來說strFiles的最後一個元素可能是空字元串
{
Get(strFile,strFolder,strFile);
}

}
}

/// <summary>
/// 下載一個文件
/// </summary>
/// <param name="strRemoteFileName">要下載的文件名</param>
/// <param name="strFolder">本地目錄(不得以\結束)</param>
/// <param name="strLocalFileName">保存在本地時的文件名</param>
public void Get(string strRemoteFileName,string strFolder,string strLocalFileName)
{
if(!bConnected)
{

Connect();
}
SetTransferType(TransferType.Binary);
if (strLocalFileName.Equals(""))
{
strLocalFileName = strRemoteFileName;
}
if(!File.Exists(strLocalFileName))
{
Stream st = File.Create(strLocalFileName);
st.Close();
}
FileStream output = new
FileStream(strFolder + "\\" + strLocalFileName,FileMode.Create);
Socket socketData = CreateDataSocket();
SendCommand("RETR " + strRemoteFileName);
if(!(iReplyCode == 150 || iReplyCode == 125
|| iReplyCode == 226 || iReplyCode == 250))

{
throw new IOException(strReply.Substring(4));
}
while(true)
{
int iBytes = socketData.Receive(buffer, buffer.Length, 0);
output.Write(buffer,0,iBytes);
if(iBytes <= 0)
{
break;
}
}
output.Close();
if (socketData.Connected)
{
socketData.Close();
}
if(!(iReplyCode == 226 || iReplyCode == 250))
{
ReadReply();
if(!(iReplyCode == 226 || iReplyCode == 250))
{

throw new IOException(strReply.Substring(4));
}
}
}

/// <summary>
/// 上傳一批文件
/// </summary>
/// <param name="strFolder">本地目錄(不得以\結束)</param>
/// <param name="strFileNameMask">文件名匹配字元(可以包含*和?)</param>
public void Put(string strFolder,string strFileNameMask)
{
string[] strFiles = Directory.GetFiles(strFolder,strFileNameMask);
foreach(string strFile in strFiles)
{
//strFile是完整的文件名(包含路徑)
Put(strFile);
}
}

/// <summary>
/// 上傳一個文件
/// </summary>
/// <param name="strFileName">本地文件名</param>
public void Put(string strFileName)
{
if(!bConnected)
{
Connect();
}
Socket socketData = CreateDataSocket();
SendCommand("STOR "+Path.GetFileName(strFileName));
if( !(iReplyCode == 125 || iReplyCode == 150) )
{
throw new IOException(strReply.Substring(4));
}
FileStream input = new
FileStream(strFileName,FileMode.Open);
int iBytes = 0;

while ((iBytes = input.Read(buffer,0,buffer.Length)) > 0)
{
socketData.Send(buffer, iBytes, 0);
}
input.Close();
if (socketData.Connected)
{
socketData.Close();
}
if(!(iReplyCode == 226 || iReplyCode == 250))
{
ReadReply();
if(!(iReplyCode == 226 || iReplyCode == 250))
{
throw new IOException(strReply.Substring(4));
}
}
}

#endregion

#region 目錄操作
/// <summary>
/// 創建目錄
/// </summary>
/// <param name="strDirName">目錄名</param>
public void MkDir(string strDirName)
{
if(!bConnected)
{
Connect();
}
SendCommand("MKD "+strDirName);
if(iReplyCode != 257)
{
throw new IOException(strReply.Substring(4));
}
}

/// <summary>
/// 刪除目錄
/// </summary>
/// <param name="strDirName">目錄名</param>
public void RmDir(string strDirName)

{
if(!bConnected)
{
Connect();
}
SendCommand("RMD "+strDirName);
if(iReplyCode != 250)
{
throw new IOException(strReply.Substring(4));
}
}

/// <summary>
/// 改變目錄
/// </summary>
/// <param name="strDirName">新的工作目錄名</param>
public void ChDir(string strDirName)
{
if(strDirName.Equals(".") || strDirName.Equals(""))
{
return;
}
if(!bConnected)
{
Connect();
}
SendCommand("CWD "+strDirName);
if(iReplyCode != 250)
{
throw new IOException(strReply.Substring(4));
}
this.strRemotePath = strDirName;
}

#endregion

/// <summary>
/// 將一行應答字元串記錄在strReply和strMsg
/// 應答碼記錄在iReplyCode
/// </summary>
private void ReadReply()
{
strMsg = "";
strReply = ReadLine();
iReplyCode = Int32.Parse(strReply.Substring(0,3));
}

/// <summary>
/// 建立進行數據連接的socket
/// </summary>
/// <returns>數據連接socket</returns>
private Socket CreateDataSocket()
{
SendCommand("PASV");
if(iReplyCode != 227)
{
throw new IOException(strReply.Substring(4));
}
int index1 = strReply.IndexOf('(');
int index2 = strReply.IndexOf(')');
string ipData =
strReply.Substring(index1+1,index2-index1-1);
int[] parts = new int[6];
int len = ipData.Length;
int partCount = 0;
string buf="";
for (int i = 0; i < len && partCount <= 6; i++)
{
char ch = Char.Parse(ipData.Substring(i,1));
if (Char.IsDigit(ch))
buf+=ch;
else if (ch != ',')
{
throw new IOException("Malformed PASV strReply: " +
strReply);
}
if (ch == ',' || i+1 == len)
{
try
{
parts[partCount++] = Int32.Parse(buf);
buf="";
}

catch (Exception)
{
throw new IOException("Malformed PASV strReply: " +
strReply);
}
}
}
string ipAddress = parts[0] + "."+ parts[1]+ "." +
parts[2] + "." + parts[3];
int port = (parts[4] << 8) + parts[5];
Socket s = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ep = new
IPEndPoint(IPAddress.Parse(ipAddress), port);
try

{
s.Connect(ep);
}
catch(Exception)
{
throw new IOException("Can't connect to remote server");
}
return s;
}

/// <summary>
/// 關閉socket連接(用於登錄以前)
/// </summary>
private void CloseSocketConnect()
{
if(socketControl!=null)
{
socketControl.Close();
socketControl = null;
}
bConnected = false;
}

/// <summary>
/// 讀取Socket返回的所有字元串
/// </summary>
/// <returns>包含應答碼的字元串列</returns>

private string ReadLine()
{
while(true)
{
int iBytes = socketControl.Receive(buffer, buffer.Length, 0);
strMsg += ASCII.GetString(buffer, 0, iBytes);
if(iBytes < buffer.Length)
{
break;
}
}
char[] seperator = {'\n'};
string[] mess = strMsg.Split(seperator);
if(strMsg.Length > 2)
{
strMsg = mess[mess.Length-2];
//seperator[0]是10,換行符是由13和0組成的,分隔後10後面雖沒有字元串,
//但也會分配為空字元串給後面(也是最後一個)字元串數組,
//所以最後一個mess是沒用的空字元串
//但為什麼不直接取mess[0],因為只有最後一行字元串應答碼與信息之間有空格
}
else
{
strMsg = mess[0];
}
if(!strMsg.Substring(3,1).Equals(" "))//返回字元串正確的是以應答碼(如220開頭,後面接一空格,再接問候字元串)
{
return ReadLine();
}
return strMsg;
}

/// <summary>
/// 發送命令並獲取應答碼和最後一行應答字元串
/// </summary>
/// <param name="strCommand">命令</param>
private void SendCommand(string strCommand)
{
Byte[] cmdBytes = ASCII.GetBytes((strCommand + "\r\n").ToCharArray());
socketControl.Send(cmdBytes, cmdBytes.Length, 0);
ReadReply();
}

#endregion
}
}

⑵ 如何用asp連接ftp伺服器

1、ftp需要對伺服器的返回信息進行應答,所以無法單獨啟動一個進程自動上傳。
2、可以採用編寫一個組件(當然你不建議,也就是別無它法了),將對ftp伺服器的通訊細節封裝其中,將一些方法譬如put/get等命令當作方法實現,根據通訊得到的伺服器應答代碼進行編程

⑶ asp 將伺服器文件傳送到另一個ftp空間

伺服器見的數據不能直接傳遞,只能通過 伺服器 2 上的程序讀取 伺服器1 上面的數據 例如:伺服器1 上通過程序 建立了一個文件,建立完成後,使用 script 來訪問伺服器2的文件,同時傳遞當前文件的路徑。 伺服器 2 上的文件響應後通過程序直接讀取 伺服器1 上 傳遞過來的路徑,然後通過 fso 直接讀取後寫入當伺服器2上

⑷ 如何使用ASP建立虛擬的FTP伺服器

● 第一步:在伺服器上建立一個資料庫(access、SQL-SERVER、MYSQL均可以),簡單一點就ACCESS吧。資料庫內建立兩個表:
上傳用戶管理用:admin(ID, Name, Password, Type)
保存上傳文件數據:files(ID, ParentID, FileName, FileLength, FileType, FileData, UpDate, UserID)。
如果FileLength=0,則表示其為文件夾,並且為每個用戶建立一個根文件夾。

● 第二步:建立用戶登陸頁面,並使用SESSION將用戶的ID保存起來,用於限制其對文件的操作。
Session("Name") = list("SName")
Session("UID") = list("ID")

● 第三步:建立用戶主頁面(顯示用戶上傳過的文件)
strSQL = "SELECT * FROM files WHERE ParentID=" & userRootID ' userRootId 為用戶根文件夾的ID
strSQL = strSQL & " AND UserID=" & SESSION("UID")
strSQL = strSQL & " ORDER BY FileName"

● 第四步:上傳文件頁面
list.AddNew
list("ParentID") = userRootID
list("FileName") = Form("Name")
list("FileLength") = Form("Length")
list("FileType") = Form("Type")
list("FileData").AppendChunk MidB(sdata,Form("Start"),Form("Length"))
list("UserID") = Session("UID")
list("UpDate") = Now()
list.Update

● 第五步:文件管理操作(使用文件的ID對文件進行表識,並且對用戶的操作進行限制)
刪除:"DELETE * FROM files WHERE ID=" & iID & " AND UserID=" & Session("UID")
下載:"SELECT * FROM files WHERE ID=" & iID & " AND UserID=" & Session("UID")

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open myConnStr
Set list = conn.Execute("SELECT * FROM files WHERE ID=" & iID & " AND UserID=" & Session("UID"))
If NOT list.EOF Then
If list("FileLength") > 0 Then
Response.AddHeader "Content-disposition", "inline; filename=" & list("FileName")
Response.ContentType = list("FileType")
Response.Binarywrite(list("FileData").GetChunk(list("FileLength")))
End If
End If

● 再完成一些其他的輔助操作頁面即可。當然由於瀏覽器的限制,文件上傳的續傳技術不能直接使用,只能通過客戶端軟體來實現。網路上有個軟體叫「上傳文件管理器」(包含ASP源代碼),實現了上面的功能。

⑸ 如何用ASP在WEB上實現FTP功能

如何用SA-FileUp上傳多個文件?

表單處理:
<%@ LANGUAGE="VBSCRIPT" %>
<HTML><HEAD>
<TITLE>多個文件上傳</TITLE>
</HEAD>
<BODY>
<% Set upl = Server.CreateObject("SoftArtisans.FileUp") %>
<% upl.Form("f1").SaveAs "C:\intels\upload1.out" %><BR>
文件1共寫入位元組數: <%=upl.Form("f1").TotalBytes%>
<% upl.Form("f2").SaveAs "C:\intels\upload2.out" %><BR>
文件2共寫入位元組數: <%=upl.Form("f2").TotalBytes%>
</BODY>
</HTML>

⑹ asp實現上傳文件到ftp伺服器

這個是可以實現的
不過實現過程就比較麻煩了,不是三兩句就說的完

⑺ asp代碼如何實現ftp式上傳功能

我暈 !ASP的無組件上傳,他本身就是本地的源碼, 完全可以在本地查看ASP的源碼,有組件上傳才看不到源碼的!

⑻ 有沒有辦法用asp實現類似ftp式的文件瀏覽功能

提供一個源碼下載,http://code.cnz.cc/2006/49520.html
當然,不能下載的就右鍵另存為,這個應該算常識,就不多說了。
--------------------------------------------------
秋憶工作室在線文件管理器 v4.4 使用說明:
系統介紹:
1、本系統由ASP編寫,在線管理文件包括上傳、下載、編輯、批量復制、批量粘貼、批量移動、批量刪除等等功能。
2、本系統代碼完全由手動編寫,不產生任何一丁點的HTML代碼冗餘。
3、文件管理界面仿照Windows資源管理器設計,文件圖標採用XP標准圖標。
4、真的多用戶管理,分管理員與普通用戶。
5、用戶密碼採用自定義MD5增強加密,暴力破解可以說沒有什麼機會。
6、每個用戶管理特定目錄,採用Session加密變數檢測,用戶不能通過修改Session值提升許可權。
7、對IE瀏覽器與Netscape瀏覽器都兼容。
8、用戶在同一時間只能在一個IP登陸,即不能同時在兩個以上IP登陸。
9、文件上傳採用 無組件(支持進度條)、AspUpLoad(支持進度條)、SA-FileUp、LyfUpload 四種組件上傳。
10、可以配置文件上傳格式和單個文件大小。
11、文件在線編輯採用FSO與ADODB.Stream,雙劍合壁,支持任何編碼文件讀取與保存。
12、文件夾在線打包、解包,可以打包下載網站文件。
13、簡單方便明了的用戶目錄空間佔用統計

⑼ asp如何實現ftp下載功能

頁面的連接給他www.xxx.com/down/123.rar這個地址.下載的時候用js把連接裡面的down改成download

⑽ 需要能夠ftp的asp源代碼

ASP + Serv-u 實現FTP的代碼
<!--#include file="md5.asp"-->
<%
'**************************************************
'* 作者:awaysrain(絕對零度) *
'* 完成時間:2003-10-10 *
'* 測試環境:WIN2000SERVER,SERV-U 4.2-beta版 *
'**************************************************
Dim iniPath,iniFileName,iniStr,tmpStr,n
Dim userName,passWord,tmp

userName = "myfso222" '用戶名
passWord = "awaysrain" '密碼
tmp = "ai" '隨機生成兩個小寫字母,(應該是隨機生成的,但是我這里省略了)
passWord = tmp & UCase(md5(passWord)) '密碼,是MD5加密過的,用動網的MD5加密程序,具體演算法是隨機生成兩位小寫字母,然後和你的密碼連接後進行MD5加密,把隨機生成的密碼和MD5加密後的結果作為密碼存放,舉個例子來說比如下面的awaysrain用戶,我的密碼為awaysrain先隨機生成兩位小寫字母ai,和我的密碼awaysrain連接得到aiawaysrain把aiawaysrain進行MD5加密得到把隨機生成兩位小寫字母ai和MD5加密後的結果連接得到密碼ai

iniPath="D:\Program Files\Serv-U" 'ini文件的路徑
iniFileName = "ServUDaemon.ini" 'ini的文件名

Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set ServUIni = fso.OpenTextFile(iniPath & "\" & iniFileName,1,false)

iniStr = ""
n = 0
addedUserList = false

Set tf = fso.CreateTextFile(iniPath & "\" & iniFileName & "._awaysrain.tmp", True)
'生成新的臨時INI文件

Do While not ServUIni.AtEndOfStream
tmpStr = ServUIni.ReadLine

If Instr("awaysrain||" & tmpStr,"awaysrain||User")>0 Then
'記錄用戶原來的數量
n = n+1
End If

If Instr("awaysrain||" & tmpStr,"awaysrain||[USER=")>0 and not addedUserList Then
'往用戶列表的部分添加現在的用戶
n = n +1
tf.WriteLine("User" & n & "=" & userName & "|1|0")
addedUserList = true
End If
tf.WriteLine(tmpStr)
Loop
ServUIni.Close

'添加新用戶的信息,具體內容可以在SERV-U中新建用戶並對照INI文件

tf.WriteLine("[USER=" & userName & "|1]") '用戶名
tf.WriteLine("Password=" & passWord) '密碼
tf.WriteLine("HomeDir=e:\temp") '主目錄
tf.WriteLine("RelPaths=1") '是否鎖定用戶於主目錄
tf.WriteLine("MaxUsersLoginPerIP=1") '相同IP同時登錄數
tf.WriteLine("SpeedLimitDown=102400") '最大下載速度
tf.WriteLine("TimeOut=600") '空閑超時時間(秒)
tf.WriteLine("Access1=E:\Temp|RLP") '可訪問目錄,可以不是一個,比如 'Access2=E:\Temp1|RLP'

tf.Close
'--------------------備份原來的INI文件--------------------------
Set f1 = fso.GetFile(iniPath & "\" & iniFileName)
f1.Copy (iniPath & "\" & iniFileName & "._awaysrain.bak")
f1.Delete
'--------------------把生成的臨時INI文件改為正式的INI--------------------------
Set f1 = fso.GetFile(iniPath & "\" & iniFileName & "._awaysrain.tmp")
f1.Copy (iniPath & "\" & iniFileName)
f1.Delete

Set fso = nothing
%>

註:以上代碼假設ServUDaemon.ini中的格式只有一個域並已經至少有一個用戶

測試的ServUDaemon.ini文件結構如下:
==================================
[Domain1]
User1=222|1|0
User2=myfso111|1|0
[USER=222|1]
Password=
HomeDir=E:\Temp
RelPaths=1
TimeOut=600
Access1=E:\Temp|RLP
[USER=myfso111|1]
Password=ai
HomeDir=e:\temp
RelPaths=1
TimeOut=600
Access1=E:\Temp|RLP

生成後的文件結構如下
==================================
[Domain1]
User1=222|1|0
User2=myfso111|1|0
User3=myfso222|1|0
[USER=222|1]
Password=
HomeDir=E:\Temp
RelPaths=1
TimeOut=600
Access1=E:\Temp|RLP
[USER=myfso111|1]
Password=ai
HomeDir=e:\temp
RelPaths=1
TimeOut=600
Access1=E:\Temp|RLP
[USER=myfso222|1]
Password=ai
HomeDir=e:\temp
RelPaths=1
TimeOut=600
Access1=E:\Temp|RLP

附MD5.ASP
==========================================
<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32

Private m_lOnBits(30)
Private m_l2Power(30)

Private Function LShift(lValue, iShiftBits)
If iShiftBits = 0 Then
LShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And 1 Then
LShift = &H80000000
Else
LShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If

If (lValue And m_l2Power(31 - iShiftBits)) Then
LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
Else
LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function

Private Function RShift(lValue, iShiftBits)
If iShiftBits = 0 Then
RShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And &H80000000 Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf iShiftBits < 0 Or iShiftBits > 31 Then
Err.Raise 6
End If

RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)

If (lValue And &H80000000) Then
RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - 1)))
End If
End Function

Private Function RotateLeft(lValue, iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - iShiftBits))
End Function

Private Function AddUnsigned(lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult

lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000

lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF)

If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If

AddUnsigned = lResult
End Function

Private Function md5_F(x, y, z)
md5_F = (x And y) Or ((Not x) And z)
End Function

Private Function md5_G(x, y, z)
md5_G = (x And z) Or (y And (Not z))
End Function

Private Function md5_H(x, y, z)
md5_H = (x Xor y Xor z)
End Function

Private Function md5_I(x, y, z)
md5_I = (y Xor (x Or (Not z)))
End Function

Private Sub md5_FF(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_F(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Sub md5_GG(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_G(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Sub md5_HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Sub md5_II(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_I(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub

Private Function ConvertToWordArray(sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount

Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448

lMessageLength = Len(sMessage)

lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - 1)

lBytePosition = 0
lByteCount = 0
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + 1, 1)), lBytePosition)
lByteCount = lByteCount + 1
Loop

lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE

lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)

lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)

ConvertToWordArray = lWordArray
End Function

Private Function WordToHex(lValue)
Dim lByte
Dim lCount

For lCount = 0 To 3
lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - 1)
WordToHex = WordToHex & Right("0" & Hex(lByte), 2)
Next
End Function
Public Function MD5(sMessage)
m_lOnBits(0) = CLng(1)
m_lOnBits(1) = CLng(3)
m_lOnBits(2) = CLng(7)
m_lOnBits(3) = CLng(15)
m_lOnBits(4) = CLng(31)
m_lOnBits(5) = CLng(63)
m_lOnBits(6) = CLng(127)
m_lOnBits(7) = CLng(255)
m_lOnBits(8) = CLng(511)
m_lOnBits(9) = CLng(1023)
m_lOnBits(10) = CLng(2047)
m_lOnBits(11) = CLng(4095)
m_lOnBits(12) = CLng(8191)
m_lOnBits(13) = CLng(16383)
m_lOnBits(14) = CLng(32767)
m_lOnBits(15) = CLng(65535)
m_lOnBits(16) = CLng(131071)
m_lOnBits(17) = CLng(262143)
m_lOnBits(18) = CLng(524287)
m_lOnBits(19) = CLng(1048575)
m_lOnBits(20) = CLng(2097151)
m_lOnBits(21) = CLng(4194303)
m_lOnBits(22) = CLng(8388607)
m_lOnBits(23) = CLng(16777215)
m_lOnBits(24) = CLng(33554431)
m_lOnBits(25) = CLng(67108863)
m_lOnBits(26) = CLng(134217727)
m_lOnBits(27) = CLng(268435455)
m_lOnBits(28) = CLng(536870911)
m_lOnBits(29) = CLng(1073741823)
m_lOnBits(30) = CLng(2147483647)

m_l2Power(0) = CLng(1)
m_l2Power(1) = CLng(2)
m_l2Power(2) = CLng(4)
m_l2Power(3) = CLng(8)
m_l2Power(4) = CLng(16)
m_l2Power(5) = CLng(32)
m_l2Power(6) = CLng(64)
m_l2Power(7) = CLng(128)
m_l2Power(8) = CLng(256)
m_l2Power(9) = CLng(512)
m_l2Power(10) = CLng(1024)
m_l2Power(11) = CLng(2048)
m_l2Power(12) = CLng(4096)
m_l2Power(13) = CLng(8192)
m_l2Power(14) = CLng(16384)
m_l2Power(15) = CLng(32768)
m_l2Power(16) = CLng(65536)
m_l2Power(17) = CLng(131072)
m_l2Power(18) = CLng(262144)
m_l2Power(19) = CLng(524288)
m_l2Power(20) = CLng(1048576)
m_l2Power(21) = CLng(2097152)
m_l2Power(22) = CLng(4194304)
m_l2Power(23) = CLng(8388608)
m_l2Power(24) = CLng(16777216)
m_l2Power(25) = CLng(33554432)
m_l2Power(26) = CLng(67108864)
m_l2Power(27) = CLng(134217728)
m_l2Power(28) = CLng(268435456)
m_l2Power(29) = CLng(536870912)
m_l2Power(30) = CLng(1073741824)

Dim x
Dim k
Dim AA
Dim BB
Dim CC
Dim DD
Dim a
Dim b
Dim c
Dim d

Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21

x = ConvertToWordArray(sMessage)

a = &H67452301
b = &HEFCDAB89
c = &H98BADCFE
d = &H10325476

For k = 0 To UBound(x) Step 16
AA = a
BB = b
CC = c
DD = d

md5_FF a, b, c, d, x(k + 0), S11, &HD76AA478
md5_FF d, a, b, c, x(k + 1), S12, &HE8C7B756
md5_FF c, d, a, b, x(k + 2), S13, &H242070DB
md5_FF b, c, d, a, x(k + 3), S14, &HC1BDCEEE
md5_FF a, b, c, d, x(k + 4), S11, &HF57C0FAF
md5_FF d, a, b, c, x(k + 5), S12, &H4787C62A
md5_FF c, d, a, b, x(k + 6), S13, &HA8304613
md5_FF b, c, d, a, x(k + 7), S14, &HFD469501
md5_FF a, b, c, d, x(k + 8), S11, &H698098D8
md5_FF d, a, b, c, x(k + 9), S12, &H8B44F7AF
md5_FF c, d, a, b, x(k + 10), S13, &HFFFF5BB1
md5_FF b, c, d, a, x(k + 11), S14, &H895CD7BE
md5_FF a, b, c, d, x(k + 12), S11, &H6B901122
md5_FF d, a, b, c, x(k + 13), S12, &HFD987193
md5_FF c, d, a, b, x(k + 14), S13, &HA679438E
md5_FF b, c, d, a, x(k + 15), S14, &H49B40821

md5_GG a, b, c, d, x(k + 1), S21, &HF61E2562
md5_GG d, a, b, c, x(k + 6), S22, &HC040B340
md5_GG c, d, a, b, x(k + 11), S23, &H265E5A51
md5_GG b, c, d, a, x(k + 0), S24, &HE9B6C7AA
md5_GG a, b, c, d, x(k + 5), S21, &HD62F105D
md5_GG d, a, b, c, x(k + 10), S22, &H2441453
md5_GG c, d, a, b, x(k + 15), S23, &HD8A1E681
md5_GG b, c, d, a, x(k + 4), S24, &HE7D3FBC8
md5_GG a, b, c, d, x(k + 9), S21, &H21E1CDE6
md5_GG d, a, b, c, x(k + 14), S22, &HC33707D6
md5_GG c, d, a, b, x(k + 3), S23, &HF4D50D87
md5_GG b, c, d, a, x(k + 8), S24, &H455A14ED
md5_GG a, b, c, d, x(k + 13), S21, &HA9E3E905
md5_GG d, a, b, c, x(k + 2), S22, &HFCEFA3F8
md5_GG c, d, a, b, x(k + 7), S23, &H676F02D9
md5_GG b, c, d, a, x(k + 12), S24, &H8D2A4C8A

md5_HH a, b, c, d, x(k + 5), S31, &HFFFA3942
md5_HH d, a, b, c, x(k + 8), S32, &H8771F681
md5_HH c, d, a, b, x(k + 11), S33, &H6D9D6122
md5_HH b, c, d, a, x(k + 14), S34, &HFDE5380C
md5_HH a, b, c, d, x(k + 1), S31, &HA4BEEA44
md5_HH d, a, b, c, x(k + 4), S32, &H4BDECFA9
md5_HH c, d, a, b, x(k + 7), S33, &HF6BB4B60
md5_HH b, c, d, a, x(k + 10), S34, &HBEBFBC70
md5_HH a, b, c, d, x(k + 13), S31, &H289B7EC6
md5_HH d, a, b, c, x(k + 0), S32, &HEAA127FA
md5_HH c, d, a, b, x(k + 3), S33, &HD4EF3085
md5_HH b, c, d, a, x(k + 6), S34, &H4881D05
md5_HH a, b, c, d, x(k + 9), S31, &HD9D4D039
md5_HH d, a, b, c, x(k + 12), S32, &HE6DB99E5
md5_HH c, d, a, b, x(k + 15), S33, &H1FA27CF8
md5_HH b, c, d, a, x(k + 2), S34, &HC4AC5665

md5_II a, b, c, d, x(k + 0), S41, &HF4292244
md5_II d, a, b, c, x(k + 7), S42, &H432AFF97
md5_II c, d, a, b, x(k + 14), S43, &HAB9423A7
md5_II b, c, d, a, x(k + 5), S44, &HFC93A039
md5_II a, b, c, d, x(k + 12), S41, &H655B59C3
md5_II d, a, b, c, x(k + 3), S42, &H8F0CCC92
md5_II c, d, a, b, x(k + 10), S43, &HFFEFF47D
md5_II b, c, d, a, x(k + 1), S44, &H85845DD1
md5_II a, b, c, d, x(k + 8), S41, &H6FA87E4F
md5_II d, a, b, c, x(k + 15), S42, &HFE2CE6E0
md5_II c, d, a, b, x(k + 6), S43, &HA3014314
md5_II b, c, d, a, x(k + 13), S44, &H4E0811A1
md5_II a, b, c, d, x(k + 4), S41, &HF7537E82
md5_II d, a, b, c, x(k + 11), S42, &HBD3AF235
md5_II c, d, a, b, x(k + 2), S43, &H2AD7D2BB
md5_II b, c, d, a, x(k + 9), S44, &HEB86D391

a = AddUnsigned(a, AA)
b = AddUnsigned(b, BB)
c = AddUnsigned(c, CC)
d = AddUnsigned(d, DD)
Next

MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
'MD5=LCase(WordToHex(b) & WordToHex(c)) 'I crop this to fit 16byte database password :D
End Function
%>

熱點內容
sql多表連接查詢 發布:2025-01-15 22:33:12 瀏覽:219
android網路休眠 發布:2025-01-15 22:32:12 瀏覽:348
怎麼不下魯大師查看電腦配置 發布:2025-01-15 22:30:23 瀏覽:309
php頁面亂碼 發布:2025-01-15 22:28:49 瀏覽:845
夢幻寶貝腳本 發布:2025-01-15 22:27:36 瀏覽:256
安卓怎麼調成2g網 發布:2025-01-15 22:21:40 瀏覽:284
android小車 發布:2025-01-15 22:21:15 瀏覽:923
微信怎麼沒有設置密碼 發布:2025-01-15 22:19:00 瀏覽:686
php判斷閏年 發布:2025-01-15 22:17:16 瀏覽:793
加密文件編號 發布:2025-01-15 21:56:56 瀏覽:437