1
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
using Kingdee.BOS.Orm.DataEntity;
|
||||
using Kingdee.BOS.Orm.Metadata.DataEntity;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Renci.SshNet;
|
||||
using Spire.Doc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Kingdee.K3.SCM.App.Stock.Report;
|
||||
using HandleUtils;
|
||||
using System.Data.SqlClient;
|
||||
using Kingdee.BOS.Util;
|
||||
using E_ZKEcc.Service;
|
||||
using E_ZKEcc.Domian;
|
||||
|
||||
namespace UnitTestProject2
|
||||
{
|
||||
[TestClass]
|
||||
@@ -57,157 +61,98 @@ namespace UnitTestProject2
|
||||
[TestMethod]
|
||||
public void TestMethod2()
|
||||
{
|
||||
// HUIWE_SFTP_TST@sftp.betagrid.gxs.com 22
|
||||
string ip = "sftp.betagrid.gxs.com";
|
||||
string port = "22";
|
||||
string user = "HUIWE_SFTP_TST";
|
||||
string pwd = "@m+n|9+v^.R}1[^";
|
||||
string localPath = "D:\\Work\\GateDge\\SFTP\\aatat.docx";
|
||||
string remotePath = "/aatat.docx";
|
||||
string remotePath = "/././POLLABLE";
|
||||
SFTPHelper SFTPHelper = new SFTPHelper(ip, user, pwd, port);
|
||||
var flag = SFTPHelper.Put(localPath, remotePath);
|
||||
var result = SFTPHelper.GetFileList(remotePath, "*BIN");
|
||||
SFTPHelper.Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
public class SFTPHelper
|
||||
[TestMethod]
|
||||
public void TestMethod4()
|
||||
{
|
||||
//var list = new List<EmployeeUpdateDomain>();
|
||||
|
||||
//list.Add(new EmployeeUpdateDomain()
|
||||
//{
|
||||
// pin = "AAA",
|
||||
// name = ""
|
||||
//});
|
||||
|
||||
//var str = JsonUtil.SerializeWithOutNull(list);
|
||||
var apiInfo = new ApiInfoDomian();
|
||||
apiInfo.appKey = "3391hexqe5h0wv4z4veju_dvn7gntnr5oiv_dxjabqtt";
|
||||
apiInfo.apiVersion = "v2";
|
||||
apiInfo.serverUrl = "http://14.21.32.187:8088";
|
||||
var service = new EmployeeService(apiInfo);
|
||||
|
||||
var data = service.GetEmployee(null);
|
||||
return;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EmployeeUpdateDomain
|
||||
{
|
||||
#region 字段或属性
|
||||
private SftpClient _sftp;
|
||||
/// <summary>
|
||||
/// SFTP连接状态
|
||||
/// 人员编号 长度为1~24个字符 必填
|
||||
/// </summary>
|
||||
public bool Connected => _sftp.IsConnected;
|
||||
#endregion
|
||||
public string pin { get; set; }
|
||||
|
||||
#region 构造
|
||||
/// <summary>
|
||||
/// 构造
|
||||
/// 名称。长度为1~20个字符
|
||||
/// </summary>
|
||||
/// <param name="ip">IP</param>
|
||||
/// <param name="port">端口</param>
|
||||
/// <param name="user">用户名</param>
|
||||
/// <param name="pwd">密码</param>
|
||||
public SFTPHelper(string ip, string user, string pwd, string port = "22")
|
||||
{
|
||||
_sftp = new SftpClient(ip, int.Parse(port), user, pwd);
|
||||
Connect();
|
||||
}
|
||||
public string name { get; set; }
|
||||
|
||||
~SFTPHelper()
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 连接SFTP
|
||||
/// <summary>
|
||||
/// 连接SFTP
|
||||
/// 人员所属部门编号(更新可以不填,新增必填)
|
||||
/// </summary>
|
||||
/// <returns>true成功</returns>
|
||||
public bool Connect()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Connected)
|
||||
{
|
||||
_sftp.Connect();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(string.Format("连接SFTP失败,原因:{0}", ex.Message));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
public string deptnumber { get; set; }
|
||||
|
||||
#region 断开SFTP
|
||||
/// <summary>
|
||||
/// 断开SFTP
|
||||
/// </summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_sftp != null && Connected)
|
||||
{
|
||||
_sftp.Disconnect();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(string.Format("断开SFTP失败,原因:{0}", ex.Message));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SFTP上传文件
|
||||
/// <summary>
|
||||
/// SFTP上传文件
|
||||
/// 性别 。'M'表示男,'F'表示女 允许值: 'M', 'F'
|
||||
/// </summary>
|
||||
/// <param name="localPath">本地文件全路径 例:G:\\Project\\logo.png</param>
|
||||
/// <param name="remotePath">远程路径 例:/logo.png</param>
|
||||
public bool Put(string localPath, string remotePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var file = File.OpenRead(localPath))
|
||||
{
|
||||
Connect();
|
||||
_sftp.UploadFile(file, remotePath);
|
||||
Disconnect();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
public string gender { get; set; }
|
||||
|
||||
#region SFTP获取文件
|
||||
/// <summary>
|
||||
/// SFTP获取文件
|
||||
/// 身份证号
|
||||
/// </summary>
|
||||
/// <param name="remotePath">远程路径</param>
|
||||
/// <param name="localPath">本地路径</param>
|
||||
public void Get(string remotePath, string localPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
Connect();
|
||||
var byt = _sftp.ReadAllBytes(remotePath);
|
||||
Disconnect();
|
||||
File.WriteAllBytes(localPath, byt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(string.Format("SFTP文件获取失败,原因:{0}", ex.Message));
|
||||
}
|
||||
public string identitycard { get; set; }
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除SFTP文件
|
||||
/// <summary>
|
||||
/// 删除SFTP文件
|
||||
/// 人员自助密码
|
||||
/// </summary>
|
||||
/// <param name="remoteFile">远程路径</param>
|
||||
public void Delete(string remoteFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
Connect();
|
||||
_sftp.Delete(remoteFile);
|
||||
Disconnect();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(string.Format("SFTP文件删除失败,原因:{0}", ex.Message));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
public string selfpassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人员是否考勤
|
||||
/// </summary>
|
||||
public int? att { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 验证方式
|
||||
/// </summary>
|
||||
public int? comverifys { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 比对照片信息,BASE64格式
|
||||
/// </summary>
|
||||
public string enrollpic { get; set; }
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethod3()
|
||||
{
|
||||
string sqlConn = "Data Source=ASSDB;User ID=ooa;Password=123qwe123";
|
||||
|
||||
SqlConnection con = new SqlConnection(sqlConn);
|
||||
//SqlConnection con = new SqlConnection("Server=.;Database=ASSDB;uid=ooa;pwd=123qwe123;Trusted_Connection=False;");
|
||||
con.Open();
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user