利用WebClient上傳檔案(底子裡好像是FTP協定)
1.FTP資訊欄位驗證 (FTP位置、FTP帳號、FTP密碼)
private Boolean doFieldsvalidation_FTP_Info()
{
Boolean rtnRetResult = false;
if (!RegExService.IPV4_FORMAT(this.tbox_FTP_Address.Text))
{
frmUtil.showMessageBox_No_Returns("非有效的IP格式");
return rtnRetResult;
}
if (tbox_FTP_ID.Text.Trim() == string.Empty)
{
frmUtil.showMessageBox_No_Returns("請輸入FTP帳號");
return rtnRetResult;
}
if (tbox_FTP_PW.Text.Trim() == string.Empty)
{
frmUtil.showMessageBox_No_Returns("請輸入FTP密碼");
return rtnRetResult;
}
rtnRetResult = true;
return rtnRetResult;
}
2.上傳檔案-webclient
private void fileUpload_WebClient(string _ip, string _id, string _pw , string[] _files)
{
string 路徑 = "ftp://" + _ip + "/";
string 檔名;
string userName = _id;
string userPwd = _pw;
try
{
WebClient wb = new WebClient();
wb.Credentials = new System.Net.NetworkCredential(userName, userPwd);
foreach (string str in _files)
{
檔名 = Path.GetFileName(str);
byte[] bytes = wb.UploadFile(路徑 + 檔名, str);
byte[] bytes1 = BitConverter.GetBytes(iPGBAR_FTP_IncreaseValue);
}
frmUtil.showMessageBox_No_Returns("上傳完畢");
}
catch (Exception e)
{
frmUtil.showMessageBox_No_Returns(e.Message);
}
finally
{
this.RequestStop();
}
}
- Jan 06 Thu 2011 12:06
C# FTP協定上傳檔案 record
全站熱搜
留言列表