FTPHelper 封裝FTP的相關操作

2021-09-30 10:38:57 字數 3151 閱讀 1179

using system;

using system.io;

using system.net;

using system.text;

namespace whir.software.datasynctools.library.helper

///

///

///

///

public ftpresult download(string localfile, string remotefile)

}catch (exception ex)

}localfilestream.close();

if (_ftpstream != null) _ftpstream.close();

_ftpresponse.close();

_ftprequest = null;

result = new ftpresult(true, "ok");

}catch (exception ex)

return result;

}/// /// 上傳檔案

///

///

///

///

public ftpresult upload(string localfile, string remotefile)

}catch (exception ex)

localfilestream.close();

_ftpstream.close();

_ftprequest = null;

result = new ftpresult(true, "ok");

}catch (exception ex)

return result;

}/// /// 刪除檔案

///

///

public ftpresult delete(string deletefile)

catch (exception ex)

return result;

}/// /// 檔案重新命名

///

///

///

///

public ftpresult rename(string currentfilenameandpath, string newfilename)

catch (exception ex)

return result;

}/// /// 建立目錄

///

///

///

public ftpresult createdirectory(string newdirectory)

catch (exception ex)

return result;

}/// /// 取得檔案建立時間

///

///

///

public ftpresult getfilecreateddatetime(string filename)

catch (exception ex)

ftpreader.close();

if (_ftpstream != null) _ftpstream.close();

_ftpresponse.close();

_ftprequest = null;

return new ftpresult(true, fileinfo);

}return new ftpresult(false, "響應流為空");

}catch (exception ex)

return result;

}/// /// 取得檔案大小

///

///

///

public ftpresult getfilesize(string filename)

}catch (exception ex)

ftpreader.close();

_ftpstream.close();

_ftpresponse.close();

_ftprequest = null;

return new ftpresult(true, fileinfo);

}result = new ftpresult(false, "響應流為空");

}catch (exception ex)

return result;

}/// /// 顯示遠端目錄結構

///

///

///

public string directorylist******(string directory)

}catch (exception ex)

ftpreader.close();

_ftpstream.close();

_ftpresponse.close();

_ftprequest = null;

try}

catch (exception ex)}}

catch (exception ex)

return new ;

}/// /// 遠端檔案列表

///

///

///

public string directorylistdetailed(string directory)

}catch (exception ex)

ftpreader.close();

_ftpstream.close();

_ftpresponse.close();

_ftprequest = null;

try}

catch (exception ex)}}

catch (exception ex)

/* return an empty string array if an exception occurs */

return new ;}}

public class ftpresult

public bool issucess

public string message

}}

FtpHelper類匿名獲取FTP檔案

using system using system.collections.generic using system.io using system.linq using system.net using system.text using system.windows.forms using te...

用socket封裝ftp類。

最近本人寫了乙個ftp類,想和大家分享一下。ftp協議的底層實現是用socket來實現的。上圖是ftp協議的官方協議圖 可以看出它主要是由兩個socket組成的。1,控制連線,主要是用於傳送控制命令 ftp協議的建立流程 首先,客戶端建立乙個套接字1,套接字繫結的ip和埠為ftp伺服器的ip和著名埠...

C 工具類 FTP操作封裝類FTPHelper

c ftphelper實現ftp伺服器檔案讀寫操作,支援ssl協議 ftp伺服器為 serv u10.0 using system using system.collections.generic using system.io using system.linq using system.net ...