这似乎是PowerShell和Visual Studio中的常见问题,但案例和解决方案似乎变化很大.虽然看到了几个类似的问题,但我还没有为我的问题找到一个可行的解决方案.
错误消息中存在此问题
无法加载文件或程序集'file:/// C:\ users\jenstmar\Desktop\WinSCP.dll'或其依赖项之一.不支持操作.(HRESULT异常:0x80131515)
文件位置无效,因为.dll应该与WinSCP安装位于同一文件夹中.此位置已更改为检查没有权利或缺少权限,限制我使用它.
导致问题的脚本行如下所示:
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("C:\users\jenstmar\Desktop\WinSCP.dll") | Out-Null
Run Code Online (Sandbox Code Playgroud)
PowerShell ISE和PS ISE(x86)中都存在此错误.我在Windows Enterprise 64位环境中以本地管理员身份运行PowerShell V3.0.我该如何解决这个问题?
我可以使用WinSCP GUI定义代理服务器.如果我这样做,我就能连接到远程主机.但在代码中我找不到为WinSCP声明代理服务器的方法.
在这种情况下,我收到了
远程服务器返回错误(407)需要代理身份验证.
我的代码:
SessionOptions sessionOptions = new SessionOptions
{
Protocol = protocol,
HostName = hostname,
UserName = user,
Password = pass,
PortNumber = portnumber
};
using (Session session = new Session())
{
session.ExecutablePath = @"C:\Program Files (x86)\WinSCP\WinSCP.exe";
session.Open(sessionOptions);
TransferOptions options = new TransferOptions();
options.FileMask = mask;
SynchronizationResult synchronizationResult;
synchronizationResult =
session.SynchronizeDirectories(mode, local, path, deletefiles, options: options);
synchronizationResult.Check();
}
Run Code Online (Sandbox Code Playgroud) 我在PS中使用WinSCP Powershell Assembly.在其中一种方法中,我使用的是WinSCP中的各种类型.
只要我已经添加了程序集,这就可以正常工作 - 但是,由于Powershell在使用类时读取脚本的方式(我假设?),在加载程序集之前会抛出错误.
实际上,即使我将Write-Host放在顶部,它也不会加载.
在解析文件的其余部分之前,有没有办法强制运行某些东西?
Transfer() {
$this.Logger = [Logger]::new()
try {
Add-Type -Path $this.Paths.WinSCP
$ConnectionType = $this.FtpSettings.Protocol.ToString()
$SessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::$ConnectionType
HostName = $this.FtpSettings.Server
UserName = $this.FtpSettings.Username
Password = $this.FtpSettings.Password
}
Run Code Online (Sandbox Code Playgroud)
Protocol = [WinSCP.Protocol] :: $ ConnectionType
无法找到类型[WinSCP.Protocol].
我正在尝试通过 WinSCP 使用 C# 连接到 FTPS 服务器,但出现此错误:
SSH 主机密钥指纹...与模式不匹配...
经过大量研究,我认为这与密钥的长度有关。在“服务器和协议信息”下使用其接口连接时,我从 WinSCP 获得的密钥是xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx 但我在示例中看到的密钥
更短,如下所示xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
有人可以帮助我并为我提供解决此问题的任何指示,将不胜感激。
这是我的代码
string winscpPath = "C:\\Program Files (x86)\\WinSCP\\WinSCP.exe";
string username = "User123";
string password = "abc1234";
string ftpSite = "192.168.5.110";
string localPath = "C:\\Users\\ttom\\Documents";
string remoteFTPDirectory = "/Usr/thisfolder";
string sshKey = "1b:68:10:80:77:c6:65:91:51:31:5t:65:1c:g6:13:20:39:g8:d8:6d";
Boolean winSCPLog = true;
string winSCPLogPath = "C:\\Users\\ttom\\Documents\\Visual Studio 2015\\Projects\\WebApplication1\\WebApplication1";
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = ftpSite,
UserName = username,
Password = password,
SshHostKeyFingerprint = sshKey
}; …Run Code Online (Sandbox Code Playgroud) 使用WinSCP的.NET程序集上传文件. OperationResultBase.Check()抛出以下错误:
WinSCP.SessionRemoteException:传输已成功完成,但临时传输文件'testfile.zip.filepart'无法重命名为目标文件名'testfile.zip'.如果问题仍然存在,您可能需要关闭传输恢复支持.
这似乎发生在我尝试发送的任何zip文件中.如果它有所不同,这些是使用DotNetZip库创建的zip文件.
我正在使用的代码,直接来自WinSCP文档中的示例:
public void uploadFile(string filePath, string remotePath)
{
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = currentSession.PutFiles(filePath, remotePath, false, transferOptions);
transferResult.Check();
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}
Run Code Online (Sandbox Code Playgroud)
在WinSCP论坛上的讨论表明,程序集还不允许以编程方式控制转移恢复支持.这有解决方法吗?
从 SFTP 访问我的远程服务器时,我不断收到此错误
连接意外关闭。服务器发送命令退出状态 0
我在 WinSCP 中填写了相同的凭据,它工作正常。我哪里欠缺?此外,我在项目用户界面的密钥文件列中使用“ssh-rsa 1024 ######################,而不是 .ppk 文件。
谢谢你,
普拉奈
我需要通过 WinSCP .NET 程序集从 FTP 下载文件。我当前有此代码,但错误显示身份验证失败。
try
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "172.xx.xxx.xx",
UserName = "usersample",
Password = "P@ssw0rd",
PortNumber = 21
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Download files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult =
session.GetFiles(
"/HST/sample.txt", "C:\\Users\\john\\Documents\\SampleFolder\\",
false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Download of {0} succeeded", transfer.FileName); …Run Code Online (Sandbox Code Playgroud) 我在 SSIS (2008) 包中有一个脚本任务,用于将文件从远程 FTP 服务器下载到本地目录。脚本任务是用 C# 2008 编写的,并使用 WinSCPnet.dll。使用 WinSCP 文档中的示例,我想出了下面的脚本。该脚本可以正确下载文件,但所有文件成功/失败消息都会保留,直到整个脚本完成,然后所有消息都会立即转储。使用 根本不显示文件进度Console.Write(),并且尝试使用Dts.Events.FireInformation()inSessionFileTransferProgress给了我
Error: "An object reference is required for the non-static field, method, or property Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase.Dts.get"
有没有办法使用 DTS.events.Fire* 事件来显示文件发生时的进度信息以及每个文件后的文件完成状态?
脚本:
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.ScriptTask;
using System.AddIn;
using WinSCP;
namespace ST_3a1cf75114b64e778bd035dd91edb5a1.csproj
{
[AddIn("ScriptMain", Version = "1.0", …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 PowerShell 并使用 WinSCP .NET 程序集连接到 SFTP 服务器。
代码无法打开会话 ( $session.Open($sessionOptions))。
在我发现的日志中,
Exception: System.MissingMethodException: Method not found: 'Void System.Threading.EventWaitHandle..ctor(Boolean, System.Threading.EventResetMode, System.String, Boolean ByRef, System.Security.AccessControl.EventWaitHandleSecurity)'. at WinSCP.ExeSessionProcess.TryCreateEvent(String name, EventWaitHandle& ev) at WinSCP.ExeSessionProcess.InitializeConsole() at WinSCP.ExeSessionProcess.Start() at WinSCP.Session.Open(SessionOptions sessionOptions) [2019-03-14 10:59:02.835Z] [0013] Session.Cleanup entering [2019-03-14 10:59:02.835Z] [0013] Terminating process
基本上,它从$session.Open($sessionOptions)to跳转到$session.Dispose()并跳过代码的其他部分。
我试图在 WinSCP 论坛上找到解决方案,但没有帮助:https ://winscp.net/forum/viewtopic.php?t
=26140
try {
Add-Type -Path "M:\AMA\ztemp_powershell\WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "abc.xyz.ca"
UserName = "abc_abc"
Password = …Run Code Online (Sandbox Code Playgroud) 使用“0”个参数调用“Check”时出现异常:“上传文件‘2019-06-11.zip’
成功,但设置权限和/或时发生错误
时间戳。
如果问题仍然存在,请关闭设置权限或保留时间戳。
或者,您可以打开“忽略权限错误”选项。
没有权限。
错误代码:3
来自服务器的错误消息:该服务器不支持修改操作
文件属性。”
行:12 字符:84
+ $session.PutFiles("D:\Users\bin\*.zip", "/Outbox/").Check <<<< ()
+ 类别信息:未指定:(:) [],MethodInitationException
+ FullQualifiedErrorId:DotNetMethodException
将文件从 Window Server 传输到 Linux 时,我不断收到上述错误文件。我在使用 WinSCP GUI 时也遇到了同样的错误。我问了MFT团队,他们没有任何设置许可。以下是我的文件传输脚本和我正在使用的软件的一些介绍版本。我因脚本或软件版本太旧而错过的任何内容?我很快就会更新服务器,但还得再等两年。该任务将被设置为调度程序,每天将文件传输到 MFT 服务器。
软件版本:
private.ppk中WinSCPNet.dllWinSCP.exeException calling "Check" with "0" argument(s): "Upload of file '2019-06-11.zip' was successful, but error occurred while setting the permissions and/or timestamp. If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on …