c# - .net使用winscp将文件从windows移动到linux
问题描述
编写代码将文件从 Windows 客户端移动到远程 linux 服务器。代码通过保持静态文件名执行得很好,但是在动态传递文件名时,代码不能按预期工作。下面是代码,请建议。谢谢,阿夫扎尔。
var psi = new System.Diagnostics.ProcessStartInfo(@"c:\Program Files (x86)\WinSCP\winscp.exe")
{
Arguments = @"/command ""option batch on"" ""option confirm off"" ""open userx:pwdx@10.1.1.1"" ""put C:\Mobile\Attachments\20.jpeg /tmp/"" ""/log=C:\Users\Administrator\Desktop\test.log"" ""exit""",//working fine
//tried this but not working @"/command ""option batch on"" ""option confirm off"" ""open auserx:pwdx@10.1.1.1"" ""put C:\Mobile\Attachments\"+filename +" "+" /tmp/"+ @"/log=C:\Users\Administrator\Desktop\test.log"" ""exit""",
//above command created file name log=C:UsersAdministratorDesktoptest.log but not the image name passed.
UseShellExecute = false,
CreateNoWindow = true
};
System.Diagnostics.Process.Start(psi);
解决方案
通过使用以下 url 中的 winscp 库和代码解决了问题。
https://winscp.net/eng/docs/library_install https://winscp.net/eng/docs/library#downloading_and_installing_the_assembly
推荐阅读
- r - 运行lda函数时不断出错
- python - Spark:将数据帧列表映射到函数的最佳策略
- angular - 如何从 Ionic 4 中的 ion-select-option 获取选择事件?
- docker - Cloud Build 如何采用动态参数来增加注册表标记?
- python - 错误:‘float’对象没有属性‘isna’”
- swift - 你将如何在 Swift 的封闭范围内振荡值?
- sql - 是否有任何包可以在 Python 中提取特定关键字
- amazon-ec2 - AWS SSM 代理 cloudwatch 资源:内存事件吗?
- php - 指定时间之前的 PHP 日期
- javascript - 使用引导程序验证复选框