public void ExportToFTP(string fullfilename,string filename)
{
DateTime dt = DateTime.Now;
string subFolder = dt.Month + "-" + dt.Day + "-" + dt.Year; string dt = @"ftp://www.aaa.com/" + subFolder + "/" +filename;
我就是想用FtpWebRequest实现上传到特定文件夹,文件夹为日期(3-21-2006),明天就把文件上传到
ftp://www.aaa.com/3-22-2006/中,现在我不知道该如何判断是否存在这个日期文件夹,如果没有我该如何创建??? FtpWebRequest request = (FtpWebRequest)WebRequest.Create(dt);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("upload", "6TXJAmrG");
StreamReader sourceStream = new StreamReader(fullfilename);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close(); request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
}
{
DateTime dt = DateTime.Now;
string subFolder = dt.Month + "-" + dt.Day + "-" + dt.Year; string dt = @"ftp://www.aaa.com/" + subFolder + "/" +filename;
我就是想用FtpWebRequest实现上传到特定文件夹,文件夹为日期(3-21-2006),明天就把文件上传到
ftp://www.aaa.com/3-22-2006/中,现在我不知道该如何判断是否存在这个日期文件夹,如果没有我该如何创建??? FtpWebRequest request = (FtpWebRequest)WebRequest.Create(dt);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("upload", "6TXJAmrG");
StreamReader sourceStream = new StreamReader(fullfilename);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close(); request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
}
解决方案 »
- 用域名登录开发的网站看到的信息和在项目中看到的不一样
- 读取二进制数据问题,急求
- 谁能给个AJAX+asp.net+POPUP弹出随时到数据库查询是否有新邮件的例子?
- asp是什么
- 如何在JS里去掉图片框的高度与宽度属性?
- 关于C#(.NET2.0)中自定义函数的问题(调用)
- 如何在对DataGrid排序的同时,又对其进行Edit,Update,Cancel等操作
- 100分,谁能写个正则表达式压缩一下HTML源码中的空白字符???
- .net FrameWork设置
- 救救我吧,DATAGRID问题,谢谢
- GridView 可以让同一字段 排成两列吗? 向各位请教
- 请问关于页面刷新重复弹出窗体的问题
string dt = @"ftp://www.aaa.com/" + subFolder + "/" +filename;
比如今天是3-21-2006日,那文件就应该上传到ftp://www.aaa.com/3-21-2006中,现在服务器中没有3-21-2006文件夹,运行出错!!!
也就是没有建立3-21-2006文件夹,现在我不知道该如何判断是否存在这个日期文件夹,如果没有我该如何创建???
public void CreateSubDirectory(string path)//---------创建目录
{
DirectoryInfo directoryInfo=new DirectoryInfo(path);
if(directoryInfo.Exists!=true)
directoryInfo.Create();
directoryInfo=null;
}
public void CreateSubDirectory(string path)//---------创建目录
{
DirectoryInfo directoryInfo=new DirectoryInfo(path);
if(directoryInfo.Exists!=true)
directoryInfo.Create();
directoryInfo=null;
}
path可以是ftp://www.aaa.com/3-16-2006/吗?
{
Stream requestStream = null;
FileStream fileStream = null;
FtpWebResponse uploadResponse = null;
try
{
FtpWebRequest uploadRequest =
(FtpWebRequest)WebRequest.Create(uploadUrl);
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile; // UploadFile is not supported through an Http proxy
// so we disable the proxy for this request.
uploadRequest.Proxy = null; requestStream = uploadRequest.GetRequestStream();
fileStream = File.Open(fileName, FileMode.Open); byte[] buffer = new byte[1024];
int bytesRead;
while (true)
{
bytesRead = fileStream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
requestStream.Write(buffer, 0, bytesRead);
} // The request stream must be closed before getting
// the response.
requestStream.Close(); uploadResponse =
(FtpWebResponse)uploadRequest.GetResponse();
Console.WriteLine("Upload complete.");
}
catch (UriFormatException ex)
{
Console.WriteLine(ex.Message);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
}
catch (WebException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (uploadResponse != null)
uploadResponse.Close();
if (fileStream != null)
fileStream.Close();
if (requestStream != null)
requestStream.Close();
}
}
{
Directory.CreateDirectory(path);
}