c#,web
已有的东西:
string[] MyFiles;
MyFiles = Directory.GetFiles(@"E:\图片\卡通\刀刀"); //得到该目录下所有文件 ,已经实现
现在想把这些文件上传到服务器"D:\新建文件夹"下面,怎么写啊??
请高人高人指点。给个单个的写法也行。
已有的东西:
string[] MyFiles;
MyFiles = Directory.GetFiles(@"E:\图片\卡通\刀刀"); //得到该目录下所有文件 ,已经实现
现在想把这些文件上传到服务器"D:\新建文件夹"下面,怎么写啊??
请高人高人指点。给个单个的写法也行。
private bool UploadToFTP(string strFilePath, string strFTPPath, string strUserName, string strPassword)
{
try
{
//Create a FTP Request Object and Specfiy a Complete Path
string strFileName = strFilePath.Substring(strFilePath.LastIndexOf("\\") + 1);
FtpWebRequest reqObj = (FtpWebRequest)WebRequest.Create(strFTPPath + @"/" + strFileName);
//Call A FileUpload Method of FTP Request Object
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
//If you want to access Resourse Protected You need to give User Name and PWD
reqObj.Credentials = new NetworkCredential(strUserName, strPassword);
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(strFilePath);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
reqObj.ContentLength = fileContents.Length;
Stream requestStream = reqObj.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)reqObj.GetResponse();
response.Close();
}
catch (Exception Ex)
{ // report error
throw Ex;
}
return true;
}