111,125
社区成员
发帖
与我相关
我的任务
分享
Uri fileUri = new Uri("ftp://localhost/tempFile/1.txt");
WebRequest request = WebRequest.Create(fileUri);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
public string[] GetFileList()
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{//
//reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/"));
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://192.168.0.1/aaa/"));
reqFTP.UseBinary = true;
//reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Credentials = new NetworkCredential("xxx", "xxxx");
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
return result.ToString().Split('\n');
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
downloadFiles = null;
return downloadFiles;
}
}
public string LoginServer()
{
request = (FtpWebRequest)FtpWebRequest.Create(_sInterface);
request.UseBinary = true;
request.KeepAlive = true;
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential(_sName, _sPassword);
try
{
response = (FtpWebResponse)request.GetResponse();
ic = request.Credentials;
return string.Empty;
}
catch (Exception ex)
{
request.Abort();
return ex.Message;
}
finally
{
if (response != null)
{
response.Close();
}
}
}
//这是我的编码,从中copy的一段