日期:2014-05-18 浏览次数:21330 次
//FTP连接取得
int lnghInet = APIs.InternetOpen("CSDN", 1, null, null, 0);
//FTP连接
int lnghConnect = APIs.InternetConnect(lnghInet, "192.168.12.12", 21, "", "", 1, 0, 0);
//改变目录
int rst = APIs.FtpSetCurrentDirectoryA(lnghConnect, source);
//成功的时候
if (rst != 0)
{
int hFind;
string strFile;
List<string> FileList = new List<string>();
APIs.WIN32_FIND_DATA findData = new APIs.WIN32_FIND_DATA();
findData.cFileName = "";
hFind = APIs.FtpFindFirstFile(lnghConnect, "*.*", ref findData, 0, 0);
//判断结果
if (hFind != 0)
{
do
{
strFile = findData.cFileName.Trim();
strFile = strFile.Substring(strFile.LastIndexOf(" ") + 1);
//取得文件夹的时候
if (findData.dwFileAttributes == 16)
{
strFile = strFile + "/";
}
FileList.Add(strFile);
}
while (APIs.InternetFindNextFileA(hFind, ref findData) != 0);
}
else
{
result = false;
return result;
}
APIs.InternetCloseHandle(lnghInet);
APIs.InternetCloseHandle(lnghConnect);
APIs.InternetCloseHandle(hFind);
}
else
{
APIs.InternetCloseHandle(lnghInet);
APIs.InternetCloseHandle(lnghConnect);
result = false;
return result;
}