我正在使用WinSCP下载和上传C#程序中的文件。我的代码看起来像这样
public Session OpenSftpSession ()
{
SessionOptions sessionOptions = new SessionOptions ();
sessionOptions.Protocol = WinSCP.Protocol.Sftp;
sessionOptions.HostName = this.hostName_;
sessionOptions.UserName = this.userName_;
sessionOptions.Password = this.password_;
sessionOptions.SshHostKeyFingerprint = this.sshHostKeyFingerprint_;
Session session = null;
try
{
session = new Session ();
session.Open (sessionOptions);
}
catch (Exception ex)
{
return null;
}
return session;
}
当程序执行行
时 session = new Session ();
它终止了。我甚至没有任何例外,它只是终止。
谢谢, 达山。
答案 0 :(得分:0)
即使遵循zmx的样本,我也遇到了同样的问题。它只是拒绝实例化Session对象。我最终做了以下(来自instructions on the WinSCP.net site):
DLL和EXE的组合使其按预期工作。只是使用DLL不起作用,因为它只是提供了一个围绕EXE的包装器。此外,旧版本的WinSCP程序集的名称为WinSCP.dll,与EXE的名称冲突;所以在bin文件夹中同时拥有DLL和EXE都不起作用。
答案 1 :(得分:0)
只需将WinScp.exe和winScp.dll粘贴到您的应用程序文件夹中,就像我一样:
ages_train, ages_test, net_worths_train, net_worths_test = train_test_split(ages, net_worths, test_size=0.1, random_state=42)
答案 2 :(得分:-1)
尝试像WinSCP website上的示例一样加载sessionOptions
。
例如,您的代码类似于:
public Session OpenSftpSession ()
{
SessionOptions sessionOptions = new SessionOptions
{
Protocol = WinSCP.Protocol.Sftp;
HostName = this.hostName_;
UserName = this.userName_;
Password = this.password_;
SshHostKeyFingerprint = this.sshHostKeyFingerprint_;
}
Session session = null;
try
{
session = new Session ();
session.Open(sessionOptions);
}
catch (Exception ex)
{
return null;
}
return session;
}