3个回答
展开全部
//这是个一个C#上传文件的例子,你参考参考
using System.Net;
using System.IO;
private FtpStatusCode UploadFun(string fileName, string uploadUrl)
{
Stream requestStream = null;
FileStream fileStream = null;
FtpWebResponse uploadResponse = null;
try
{
FtpWebRequest uploadRequest =
(FtpWebRequest)WebRequest.Create(uploadUrl);
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;
uploadRequest.Proxy = null;
NetworkCredential nc = new NetworkCredential();
nc.UserName = "aa";
nc.Password = "aa123";
uploadRequest.Credentials = nc; //修改getCredential();错误2
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);
}
requestStream.Close();
uploadResponse = (FtpWebResponse)uploadRequest.GetResponse();
return uploadResponse.StatusCode;
}
catch (UriFormatException ex)
{
}
catch (IOException ex)
{
}
catch (WebException ex)
{
}
finally
{
if (uploadResponse != null)
uploadResponse.Close();
if (fileStream != null)
fileStream.Close();
if (requestStream != null)
requestStream.Close();
}
return FtpStatusCode.Undefined;
}
//这么调用:
FtpStatusCode status = UploadFun(@"d:\1\1.txt", "ftp://域名/目录/保存文件名");
展开全部
更多追问追答
追问
关键是ftp是个空间 数据库也个空间 他俩有什么区别呢?
追答
你在网上买的空间吧? 这两个空间都是磁盘空间,都可以直接ftp上传文件,只是目录不同~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-01-15
展开全部
C语言代码
追问
c# 的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询