|
|
|
@ -1236,6 +1236,7 @@ namespace DSWeb.Areas.Dispatch.Controllers
|
|
|
|
|
var SftpUserName = WebConfigurationManager.AppSettings["SWISftpUserName"].ToString();
|
|
|
|
|
var SftpPassword = WebConfigurationManager.AppSettings["SWISftpPassword"].ToString();
|
|
|
|
|
var SftpPath= WebConfigurationManager.AppSettings["SWISftpPath"].ToString();
|
|
|
|
|
var SftpSiPath = WebConfigurationManager.AppSettings["SWISftpSiPath"].ToString();
|
|
|
|
|
|
|
|
|
|
var str = "";
|
|
|
|
|
try
|
|
|
|
@ -1263,22 +1264,240 @@ namespace DSWeb.Areas.Dispatch.Controllers
|
|
|
|
|
|
|
|
|
|
TransferOptions transferOptions = new TransferOptions();
|
|
|
|
|
transferOptions.TransferMode = TransferMode.Binary;
|
|
|
|
|
transferOptions.PreserveTimestamp = true;
|
|
|
|
|
transferOptions.PreserveTimestamp = false;
|
|
|
|
|
TransferOperationResult transferResult;
|
|
|
|
|
transferResult = session.PutFiles(filename, SftpPath + name, false, transferOptions);
|
|
|
|
|
transferResult = session.PutFiles(filename, SftpPath, false, transferOptions);
|
|
|
|
|
transferResult.Check();
|
|
|
|
|
if (transferResult.IsSuccess)
|
|
|
|
|
//if (transferResult.IsSuccess)
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
foreach (TransferEventArgs transfer in transferResult.Transfers)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
//else {
|
|
|
|
|
// result.Success = false;
|
|
|
|
|
// result.Message = "传输过程出现错误";
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (session != null)
|
|
|
|
|
{
|
|
|
|
|
session.Dispose();
|
|
|
|
|
}
|
|
|
|
|
// 你的代码
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
|
|
result.Message = "上传成功!";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = E.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var jsonRespose2 = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
|
|
|
return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose2) };
|
|
|
|
|
}
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ContentResult SftpSiFilesSWIJF()
|
|
|
|
|
{
|
|
|
|
|
var result = new DBResult();
|
|
|
|
|
var jsonRespose = new JsonResponse { Success = false, Message = "" };
|
|
|
|
|
|
|
|
|
|
if (Request.Files.Count != 1)
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = "请选择上传的文件";
|
|
|
|
|
return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var file = Request.Files["filename"];
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
|
|
|
|
|
return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
var name = Path.GetFileName(file.FileName);
|
|
|
|
|
var path = Server.MapPath("../../UploadFiles");
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
}
|
|
|
|
|
string filename = path + "\\" + name;
|
|
|
|
|
|
|
|
|
|
if (System.IO.File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
System.IO.File.Delete(filename);
|
|
|
|
|
}
|
|
|
|
|
file.SaveAs(filename);
|
|
|
|
|
var keypath = Server.MapPath("../../ExpFiles");
|
|
|
|
|
string keyfile = keypath + "\\SWIPrivate.ppk";
|
|
|
|
|
var SshHostKeyFingerprint = WebConfigurationManager.AppSettings["SWIJFSshHostKeyFingerprint"].ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(SshHostKeyFingerprint)) SshHostKeyFingerprint = "ssh-rsa 2048 EcxSghC0Z/Vm+FO7cHEJspEPdB6e9hb12zOPQgMMjUk";
|
|
|
|
|
var SftpServier = WebConfigurationManager.AppSettings["SWISftpServier"].ToString();
|
|
|
|
|
var SftpPort = WebConfigurationManager.AppSettings["SWISftpPort"].ToString();
|
|
|
|
|
var SftpUserName = WebConfigurationManager.AppSettings["SWISftpUserName"].ToString();
|
|
|
|
|
var SftpPassword = WebConfigurationManager.AppSettings["SWISftpPassword"].ToString();
|
|
|
|
|
var SftpPath = WebConfigurationManager.AppSettings["SWISftpPath"].ToString();
|
|
|
|
|
var SftpSiPath = WebConfigurationManager.AppSettings["SWISftpSiPath"].ToString();
|
|
|
|
|
|
|
|
|
|
var str = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 配置会话选项
|
|
|
|
|
SessionOptions sessionOptions = new SessionOptions
|
|
|
|
|
{
|
|
|
|
|
Protocol = Protocol.Sftp,
|
|
|
|
|
HostName = SftpServier,
|
|
|
|
|
PortNumber = Convert.ToInt32(SftpPort),
|
|
|
|
|
UserName = SftpUserName,
|
|
|
|
|
Password = SftpPassword,
|
|
|
|
|
SshHostKeyFingerprint = SshHostKeyFingerprint,
|
|
|
|
|
|
|
|
|
|
SshPrivateKeyPath = keyfile,
|
|
|
|
|
|
|
|
|
|
PrivateKeyPassphrase = SftpPassword,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sessionOptions.AddRawSettings("KEX", "rsa,ecdh,dh-gex-sha1,dh-group14-sha1,WARN,dh-group1-sha1");
|
|
|
|
|
|
|
|
|
|
using (Session session = new Session())
|
|
|
|
|
{
|
|
|
|
|
session.Open(sessionOptions);
|
|
|
|
|
|
|
|
|
|
TransferOptions transferOptions = new TransferOptions();
|
|
|
|
|
transferOptions.TransferMode = TransferMode.Binary;
|
|
|
|
|
transferOptions.PreserveTimestamp = false;
|
|
|
|
|
TransferOperationResult transferResult;
|
|
|
|
|
transferResult = session.PutFiles(filename, SftpSiPath, false, transferOptions);
|
|
|
|
|
transferResult.Check();
|
|
|
|
|
//if (transferResult.IsSuccess)
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
foreach (TransferEventArgs transfer in transferResult.Transfers)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
//else {
|
|
|
|
|
// result.Success = false;
|
|
|
|
|
// result.Message = "传输过程出现错误";
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (session != null)
|
|
|
|
|
{
|
|
|
|
|
session.Dispose();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// 你的代码
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.Success = true;
|
|
|
|
|
result.Message = "上传成功!";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
|
|
|
|
result.Success = false;
|
|
|
|
|
result.Message = "传输过程出现错误";
|
|
|
|
|
result.Message = E.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var jsonRespose2 = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
|
|
|
return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose2) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ContentResult SftpVgmFilesSWIJF()
|
|
|
|
|
{
|
|
|
|
|
var result = new DBResult();
|
|
|
|
|
var jsonRespose = new JsonResponse { Success = false, Message = "" };
|
|
|
|
|
|
|
|
|
|
if (Request.Files.Count != 1)
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = "请选择上传的文件";
|
|
|
|
|
return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var file = Request.Files["filename"];
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
|
|
|
|
|
return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
var name = Path.GetFileName(file.FileName);
|
|
|
|
|
var path = Server.MapPath("../../UploadFiles");
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
}
|
|
|
|
|
string filename = path + "\\" + name;
|
|
|
|
|
|
|
|
|
|
if (System.IO.File.Exists(filename))
|
|
|
|
|
{
|
|
|
|
|
System.IO.File.Delete(filename);
|
|
|
|
|
}
|
|
|
|
|
file.SaveAs(filename);
|
|
|
|
|
var keypath = Server.MapPath("../../ExpFiles");
|
|
|
|
|
string keyfile = keypath + "\\SWIPrivate.ppk";
|
|
|
|
|
var SshHostKeyFingerprint = WebConfigurationManager.AppSettings["SWIJFSshHostKeyFingerprint"].ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(SshHostKeyFingerprint)) SshHostKeyFingerprint = "ssh-rsa 2048 EcxSghC0Z/Vm+FO7cHEJspEPdB6e9hb12zOPQgMMjUk";
|
|
|
|
|
var SftpServier = WebConfigurationManager.AppSettings["SWISftpServier"].ToString();
|
|
|
|
|
var SftpPort = WebConfigurationManager.AppSettings["SWISftpPort"].ToString();
|
|
|
|
|
var SftpUserName = WebConfigurationManager.AppSettings["SWISftpUserName"].ToString();
|
|
|
|
|
var SftpPassword = WebConfigurationManager.AppSettings["SWISftpPassword"].ToString();
|
|
|
|
|
var SftpVgmPath = WebConfigurationManager.AppSettings["SWISftpVgmPath"].ToString();
|
|
|
|
|
|
|
|
|
|
var str = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 配置会话选项
|
|
|
|
|
SessionOptions sessionOptions = new SessionOptions
|
|
|
|
|
{
|
|
|
|
|
Protocol = Protocol.Sftp,
|
|
|
|
|
HostName = SftpServier,
|
|
|
|
|
PortNumber = Convert.ToInt32(SftpPort),
|
|
|
|
|
UserName = SftpUserName,
|
|
|
|
|
Password = SftpPassword,
|
|
|
|
|
SshHostKeyFingerprint = SshHostKeyFingerprint,
|
|
|
|
|
|
|
|
|
|
SshPrivateKeyPath = keyfile,
|
|
|
|
|
|
|
|
|
|
PrivateKeyPassphrase = SftpPassword,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sessionOptions.AddRawSettings("KEX", "rsa,ecdh,dh-gex-sha1,dh-group14-sha1,WARN,dh-group1-sha1");
|
|
|
|
|
|
|
|
|
|
using (Session session = new Session())
|
|
|
|
|
{
|
|
|
|
|
session.Open(sessionOptions);
|
|
|
|
|
|
|
|
|
|
TransferOptions transferOptions = new TransferOptions();
|
|
|
|
|
transferOptions.TransferMode = TransferMode.Binary;
|
|
|
|
|
transferOptions.PreserveTimestamp = false;
|
|
|
|
|
TransferOperationResult transferResult;
|
|
|
|
|
transferResult = session.PutFiles(filename, SftpVgmPath, false, transferOptions);
|
|
|
|
|
transferResult.Check();
|
|
|
|
|
//if (transferResult.IsSuccess)
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
foreach (TransferEventArgs transfer in transferResult.Transfers)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
//else {
|
|
|
|
|
// result.Success = false;
|
|
|
|
|
// result.Message = "传输过程出现错误";
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (session != null)
|
|
|
|
|
{
|
|
|
|
@ -1302,6 +1521,7 @@ namespace DSWeb.Areas.Dispatch.Controllers
|
|
|
|
|
return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose2) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ContentResult SftpFilesYT()
|
|
|
|
|
{
|
|
|
|
|