我正在尝试使用WinSCP将文件传输到服务器。
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = ftpurl,
UserName = ftpusername,
Password = ftppassword
//,
//GiveUpSecurityAndAcceptAnySshHostKey = true
};
string filename = Path.GetFileName(sourcefilepath);
string ftpfullpath = ftpurl + "/" + filename;
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Automatic;
TransferOperationResult transferResult = session.PutFiles(sourcefilepath, ftpfilepath, true, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
success = true;
}
}
在上面的代码中,我的 remotePath 是 ftpfilepath 。
TransferOperationResult transferResult = session.PutFiles(sourcefilepath,ftpfilepath,true,transferOptions);
但是由于用户名被追加到路径中,所以我遇到了异常。
传输文件'D:\ Document \ Invoices \ S585.IN.PDF.TRIG.SHIP.R7114002'时出错。 将文件复制到远程端失败。 SVC99返回码= 4 S99INFO = 0 S99ERROR = 38668 HEX = 970C S99ERSN码X'000042CE'。 无法为STOR命令创建数据集UserName.S585。
您能告诉我如何避免添加用户名。或文件传输错误的原因可能是什么。