網(wǎng)站首頁 編程語言 正文
一、建立連接
public string connectFTP(string vPath, string vUID, string vPassword)
{
string errormsg = "";
Process proc = new Process();
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string dosLine = "net use " + vPath + " " + vPassword + " /user:" + vUID;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
errormsg = proc.StandardError.ReadToEnd();
proc.StandardError.Close();
}
catch (Exception ex)
{
//throw ex;
//MessageBox.Show(ex.Message);
}
finally
{
proc.Close();
proc.Dispose();
}
return errormsg;
}
二、上傳文件
public void UploadFile(string vPath, string vUID, string vPassword, string vLocalPath, string file)
{
bool status = false;
status = connectState(vPath, vUID, vPassword);
if (status)
{
DirectoryInfo theFolder = new DirectoryInfo(vPath + "/" + file);
string filename = vLocalPath;
Transport(vLocalPath, vPath + "/" + file);
//System.Diagnostics.Process.Start(vPath);
}
else
{
mesLog.Info("未能連接!");
//MessageBox.Show("未能連接!");
}
}
三、連接狀態(tài)
public static bool connectState(string vPath, string vUID, string vPassword)
{
bool Flag = false;
Process proc = new Process();
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string dosLine = "net use " + vPath + " " + vPassword + " /user:" + vUID;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
string errormsg = proc.StandardError.ReadToEnd();
proc.StandardError.Close();
if (string.IsNullOrEmpty(errormsg))
{
Flag = true;
}
else
{
throw new Exception(errormsg);
}
}
catch (Exception ex)
{
//throw ex;
//MessageBox.Show(ex.Message);
}
finally
{
proc.Close();
proc.Dispose();
}
return Flag;
}
四、傳送
public static void Transport(string src, string fileName)
{
FileStream inFileStream = new FileStream(src, FileMode.Open);
FileStream outFileStream = new FileStream(fileName, FileMode.OpenOrCreate);
byte[] buf = new byte[inFileStream.Length];
int byteCount;
while ((byteCount = inFileStream.Read(buf, 0, buf.Length)) > 0)
{
outFileStream.Write(buf, 0, byteCount);
}
inFileStream.Flush();
inFileStream.Close();
outFileStream.Flush();
outFileStream.Close();
File.Delete(src);
}
原文鏈接:https://www.cnblogs.com/wml-it/p/15188139.html
相關推薦
- 2022-01-31 torch.save實現(xiàn)對網(wǎng)絡結構和模型參數(shù)的保存 & pytorch模型文件.pt .pt
- 2022-09-02 ahooks整體架構及React工具庫源碼解讀_React
- 2022-10-14 Sklearn中predict_proba函數(shù)用法及原理詳解
- 2022-04-12 C#實現(xiàn)六大設計原則之單一職責原則_C#教程
- 2022-09-08 python?中Mixin混入類的使用方法詳解_python
- 2022-08-06 C#使用Tesseract進行Ocr識別的方法實現(xiàn)_C#教程
- 2023-10-28 C++?string和wstring相互轉換方式_C 語言
- 2022-04-03 django中websocket的具體使用_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支