linux ftp 客户端验证,C# linux FTP client [客户端]
///
/// 图片浏览
///
///
///
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "打开(Open)";
ofd.FileName = "";
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//为了获取特定的系统文件夹,可以使用System.Environment类的静态方法GetFolderPath()。该方法接受一个 Environment.SpecialFolder枚举,其中可以定义要返回路径的哪个系统目录
ofd.Filter = "CSV文件(*.jpg)|*.jpg";
ofd.ValidateNames = true; //文件有效性验证ValidateNames,验证用户输入是否是一个有效的Windows文件名
ofd.CheckFileExists = true; //验证路径有效性
ofd.CheckPathExists = true; //验证文件有效性
if (ofd.ShowDialog() == DialogResult.OK)
{
filepath = ofd.FileName.Substring(0, ofd.FileName.Length - ofd.SafeFileName.Length - 1);
filepath = filepath.Replace("/", @"\\\\");
filename = ofd.SafeFileName;
textBox4.Text = filepath + @"\\" + filename;
}
}
///
/// FTP 上传
///
///
///
private void button2_Click_1(object sender, EventArgs e)
{
file_name_url_image_d = "mili" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".jpg";
FtpStatusCode status = UploadFun(textBox4.Text, "ftp://203.86.26.190/milimall/images_d/images/upload/" + file_name_url_image_d);
FtpStatusCode status2 = UploadFun(textBox4.Text, "ftp://203.86.26.190/milimall/images/upload/Image/" + file_name_url_image_d);
if (status.ToString() == "ClosingData" && status2.ToString() == "ClosingData")
{
MessageBox.Show("上传成功");
MessageBox.Show("ftp://203.86.26.190/milimall/images_d/images/upload/Image/" + file_name_url_image_d);
mark_upload = true;
}
else
{
file_name_url_image_d = "";
MessageBox.Show("上传失败");
}
}
#region FTP 上传类
///
/// FTP 上传类
///
///
///
///
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.Domain = "203.86.26.190";
nc.UserName = "milimall";
nc.Password = "wesdxc91";
// uploadRequest.UseBinary = true;
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;
}
#endregion
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)