日期:2011-07-18 浏览次数:20508 次
using System.Net;
using System.IO;
using System.Text;
using System.Net.Sockets;
调用示例:
//调用开始:
FTPClient FtpNiuGames=new FTPClient();
FtpNiuGames.RemoteHost=textBox3.Text;
FtpNiuGames.RemoteUser=textBox5.Text;
FtpNiuGames.RemotePass=textBox6.Text;
FtpNiuGames.RemotePath=txtFtpDir.Text;;
FtpNiuGames.RemotePort=int.Parse(textBox7.Text);
FtpNiuGames.Connect();
textBox8.Text="成功打开FTP连接";
//FtpNiuGames.Get("SHNiugames.mdb","c:\\");
FtpNiuGames.Get(strFtpFile,strLocalDir);
textBox8.Text=textBox8.Text + "\r\nFTP文件:"+strFtpDir+"文件到本地:" +strLocalFilePath+ "完成";
FtpNiuGames.DisConnect();
textBox8.Text=textBox8.Text + "\r\n成功关闭FTP连接";
//调用完成
/// <summary>
/// FTP Client
/// </summary>
public class FTPClient
{
#region 构造函数
/// <summary>
/// 缺省构造函数
/// </summary>
public FTPClient()
{
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 FTPClient( 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>
private string strRemoteHost;
public string RemoteHost
{
get
{
return strRemoteHost;
}
set
{
strRemoteHost = value;
}
}
/// <summary>
/// FTP服务器端口
/// </summary>
private int strRemotePort;
public int RemotePort
{
get
{
return strRemotePort;
}
set
{
strRemotePort = value;
}
}
/// <summary>
/// 当前服务器目录
/// </summary>
private string strRemotePath;
public string RemotePath
{
get
{
return strRemotePath;
}
set
{
strRemotePath = value;
&nbs