用的是support.dll,从这里下载。
用的时候需要先引用这个dll,然后using FtpSupport;
下面是ftp上传代码:
/// <summary>
/// ftp上传
/// </summary>
/// <param name="localFile">形如 Server.MapPath("~/")+"log.txt"</param>
/// <param name="dr">ftp服务器端目录名称,形如/vagerent/image/</param>
/// <param name="newRemoteFile">传到服务器后的文件名称,比如log.txt</param>
/// <returns></returns>
private int FtpFile(string localFile,string dr,string newRemoteFile)
{
string remoteDr = "/";
FtpConnection ftp = new FtpConnection();
try
{
string ftpIP = ConfigurationSettings.AppSettings["ftpIP"];
string ftpUsrName = ConfigurationSettings.AppSettings["ftpUsrName"];
string ftpUsrPsw = ConfigurationSettings.AppSettings["ftpUsrPsw"];
ftp.Connect(ftpIP,ftpUsrName,ftpUsrPsw);
remoteDr = dr;
ftp.SetCurrentDirectory(remoteDr);
ftp.PutFile(localFile,newRemoteFile);
return 1;//上传成功
}
catch (Exception err)
{
return 0;//上传失败
}
finally
{
ftp.Close();
}
}
/// ftp上传
/// </summary>
/// <param name="localFile">形如 Server.MapPath("~/")+"log.txt"</param>
/// <param name="dr">ftp服务器端目录名称,形如/vagerent/image/</param>
/// <param name="newRemoteFile">传到服务器后的文件名称,比如log.txt</param>
/// <returns></returns>
private int FtpFile(string localFile,string dr,string newRemoteFile)
{
string remoteDr = "/";
FtpConnection ftp = new FtpConnection();
try
{
string ftpIP = ConfigurationSettings.AppSettings["ftpIP"];
string ftpUsrName = ConfigurationSettings.AppSettings["ftpUsrName"];
string ftpUsrPsw = ConfigurationSettings.AppSettings["ftpUsrPsw"];
ftp.Connect(ftpIP,ftpUsrName,ftpUsrPsw);
remoteDr = dr;
ftp.SetCurrentDirectory(remoteDr);
ftp.PutFile(localFile,newRemoteFile);
return 1;//上传成功
}
catch (Exception err)
{
return 0;//上传失败
}
finally
{
ftp.Close();
}
}