上传文件到ftp 报错
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/09/20 06:12:19
上传文件到ftp 报错
private static void doUploadFile(string filename)
{
string ftpServer = ConfigurationSettings.AppSettings["FTPServer"].ToString();
string ftpUser = ConfigurationSettings.AppSettings["FTPUser"].ToString();
string ftpPwd = ConfigurationSettings.AppSettings["FTPPwd"].ToString();
string ftpDir = ConfigurationSettings.AppSettings["FTPDirectory"].ToString();
FileInfo fileInf = new FileInfo(filename);
string serverpath=ftpServer+"/"+"d:/"+ftpDir;
string uri = "ftp://" + ftpServer + "/" + fileInf.Name;
FtpWebRequest reqFTP;
// 根据uri创建FtpWebRequest对象
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + serverpath + "/" + fileInf.Name));
// ftp用户名和密码
reqFTP.Credentials = new NetworkCredential(ftpUser,ftpPwd);
// 默认为true,连接不会被关闭
// 在一个命令之后被执行
reqFTP.KeepAlive = false;
// 指定执行什么命令
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// 指定数据传输类型
reqFTP.UseBinary = true;
// 上传文件时通知服务器文件的大小
reqFTP.ContentLength = fileInf.Length;
// 缓冲大小设置为2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
// 打开一个文件流 (System.IO.FileStream) 去读上传的文件
FileStream fs = fileInf.OpenRead();
try
{
// 把上传的文件写入流
Stream strm = reqFTP.GetRequestStream();
// 每次读文件流的2kb
contentLen = fs.Read(buff,0,buffLength);
// 流内容没有结束
while (contentLen = 0)
{
// 把内容从file stream 写入 upload stream
strm.Write(buff,0,contentLen);
contentLen = fs.Read(buff,0,buffLength);
}
// 关闭两个流
strm.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Upload Error");
}
}问题补充:
Stream strm = reqFTP.GetRequestStream();
这里读的时候他就报错error:The remote server returned an error:(550) File unavailable (e.g.,file not found,no access).
private static void doUploadFile(string filename)
{
string ftpServer = ConfigurationSettings.AppSettings["FTPServer"].ToString();
string ftpUser = ConfigurationSettings.AppSettings["FTPUser"].ToString();
string ftpPwd = ConfigurationSettings.AppSettings["FTPPwd"].ToString();
string ftpDir = ConfigurationSettings.AppSettings["FTPDirectory"].ToString();
FileInfo fileInf = new FileInfo(filename);
string serverpath=ftpServer+"/"+"d:/"+ftpDir;
string uri = "ftp://" + ftpServer + "/" + fileInf.Name;
FtpWebRequest reqFTP;
// 根据uri创建FtpWebRequest对象
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + serverpath + "/" + fileInf.Name));
// ftp用户名和密码
reqFTP.Credentials = new NetworkCredential(ftpUser,ftpPwd);
// 默认为true,连接不会被关闭
// 在一个命令之后被执行
reqFTP.KeepAlive = false;
// 指定执行什么命令
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// 指定数据传输类型
reqFTP.UseBinary = true;
// 上传文件时通知服务器文件的大小
reqFTP.ContentLength = fileInf.Length;
// 缓冲大小设置为2kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
// 打开一个文件流 (System.IO.FileStream) 去读上传的文件
FileStream fs = fileInf.OpenRead();
try
{
// 把上传的文件写入流
Stream strm = reqFTP.GetRequestStream();
// 每次读文件流的2kb
contentLen = fs.Read(buff,0,buffLength);
// 流内容没有结束
while (contentLen = 0)
{
// 把内容从file stream 写入 upload stream
strm.Write(buff,0,contentLen);
contentLen = fs.Read(buff,0,buffLength);
}
// 关闭两个流
strm.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Upload Error");
}
}问题补充:
Stream strm = reqFTP.GetRequestStream();
这里读的时候他就报错error:The remote server returned an error:(550) File unavailable (e.g.,file not found,no access).
eqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + serverpath + "/" + fileInf.Name));
你serverpath 包含d: 肯定不对了
应该是ftp路径
再问: 我的路径是放在ftp ://的d目录下 就算我去掉还是报错
再答: 你的ftp路径是怎么样的 你在文件夹地址输入那个路径能访问吗 如果不能 那么程序也不能
你serverpath 包含d: 肯定不对了
应该是ftp路径
再问: 我的路径是放在ftp ://的d目录下 就算我去掉还是报错
再答: 你的ftp路径是怎么样的 你在文件夹地址输入那个路径能访问吗 如果不能 那么程序也不能
上传文件到ftp 报错
在win7中上传文件出现 java.io.IOException:fail to upload 报错
英语翻译这是一个匿名FTP服务器.任何人都可以往incoming目录中上传文件,这个目录包括子目录中的任何文件并不受我们
pro/e制图求助请将文件上传到知道
三、计算机选择题A.FTP站点B.FTP站点的一个文件夹C.FTP站点的一个文件D.地址表示错误满分:5 分2.发现计算
用ftp上传东西 421 Too many connections (8) from this IP
文件上传者用英语怎么说?
七下英语课时作业本 上传文件
英语翻译------------------------------------您好(ab001、cd33)文件已上传,
求英语单词MP3,单词发音+拼写+汉语的MP3文件 上传到知道或者发二三四二零零一八一 越多越好
求英语翻译:你能够联系迈克解决FTP文件的问题吗?
求新东方新概念英语291到96课精讲笔记.【百度文库里有,我没财富了】求在此上传文件.