FTP下载文件问题,急!!!!
private void button3_Click(object sender, EventArgs e)
{
string KSSJ = dtpKSSJ.Value.ToString("yyyy-MM-dd");
string SavePath = this.textBox1.Text;
string ftpUrl = "";
if (this.textBox1.Text.Trim() != "")
{
if (dataGridView1.Rows.Count > 0)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (bool.Parse(dataGridView1.Rows[i].Cells[9].Value.ToString()) == false)
{
string FileName = this.dataGridView1.Rows[i].Cells[0].Value.ToString();//获取FTP文件名
string FilePath1 = this.dataGridView1.Rows[i].Cells[4].Value.ToString();//获取FTP文件路径
string FilePath2 = FilePath1.Substring(0, FilePath1.Length - 1);
ftpUrl = FilePath2.Substring(1);
string Model_No = this.dataGridView1.Rows[i].Cells[5].Value.ToString();//获取型号
string Type_Work = this.dataGridView1.Rows[i].Cells[6].Value.ToString();//获取工种
int FileSize = Convert.ToInt32(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
string path = string.Format(@"{0}\{1}\{2}\{3}\", SavePath, KSSJ, Model_No, Type_Work);
string url = "ftp://15.5.240.15/" + ftpUrl;
// DownLoad(FileName, ftpUrl, SavePath, KSSJ, Model_No, Type_Work);
Download(FileName, url, path,FileSize);
//MessageBox.Show("可以保存!");
}
}
}
else
{
MessageBox.Show("没有指定数据!");
}
}
else
{
MessageBox.Show("请指定存放目录!", "提示");
}
}
/// <summary>
/// 下载
/// </summary>
/// <param name="FileName"></param>
/// <param name="ftpUrl"></param>
/// <param name="path"></param>
public void Download(string FileName, string ftpUrl, string path,int FileSize)
{
FtpWebRequest reqFTP;
try
{
FileStream outputStream = new FileStream(path + "\\" + FileName, FileMode.Create);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpUrl + FileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.KeepAlive = false;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential("bft1", "Aa149608");
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = FileSize;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}
ftpStream.Close();
outputStream.Close();
response.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
麻烦各位大大帮忙看下,为什么报错:未能找到路径“C:\Users\Administrator\Desktop\新建文件夹\2015-03-01\CBL7501A\LTE-TDD\1.txt”的一部分
...全文
相关推荐
python从FTP上下载文件
python从FTP上下载文件,python搜集的FTP下载文件汇总,网上收集
用C#实现文件上传到FTP,从ftp下载,读取文件
用C#实现文件上传到FTP,从ftp下载,读取文件
C#下载ftp指定目录下所有文件
C#下载ftp指定目录下所有文件。ftp地址、目录名、保存路径都写入了代码中,用户可根据需要自己修改即可。可下载目录下所有文件和文件夹。注解较少,我也是参照网上写的,本机运行正常。
java实现Ftp批量下载文件及解压
java实现连接登录Ftp,下载Ftp指定文件夹下的所有文件,并解压所有压缩文件,同时支持对指定文件夹进行文件压缩
linux命令行下的ftp 多文件下载和目录下载
linux命令行下的ftp 多文件下载和目录下载,这个可以解决很多问题哦!


