Muh*_*nan 1 c# sftp winscp winscp-net
我正在尝试使用以下代码上传文件,但在下面收到错误.
一些注意事项:我正在使用Windows 7.使用CrushFTP SFTP服务器,能够使用FileZilla和WinSCP客户端连接,但通过代码它是噩梦.
错误/例外:
mscorlib.dll中发生了'System.IO.IOException'类型的第一次机会异常
附加信息:进程无法访问文件'C:\ Users\xxxxxxx\AppData\Local\Temp\wscp0D64.036B20B7.tmp',因为它正由另一个进程使用.
我的连接代码如下
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "127.0.0.1", //hostname e.g. IP: 192.54.23.32, or mysftpsite.com
UserName = "xxxxxx",
Password = "yyyyyy",
PortNumber = zzzzz, //some number
SshHostKeyFingerprint = "ssh-rsa 1024 ::::04:85:3b:7a::::::::"
};
using (Session session = new Session())
{
session.Open(sessionOptions); //Attempts to connect to your sFtp site
//Get Ftp File
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary; //The Transfer Mode -
// Automatic, Binary, or Ascii
transferOptions.FilePermissions = null; //Permissions applied to remote files;
//null for default permissions. Can set user,
//Group, or other Read/Write/Execute permissions.
transferOptions.PreserveTimestamp = false; //Set last write time of
//destination file to that of source file - basically change the timestamp
//to match destination and source files.
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;
TransferOperationResult transferResult;
//the parameter list is: local Path, Remote Path, Delete source file?, transfer Options
transferResult = session.PutFiles(@"C:\Adnan\a.txt", "/", false, transferOptions);
//Throw on any error
transferResult.Check();
//Log information and break out if necessary
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我也遇到过这个例外.对我来说,它是在调用session.Open(...)时生成的.
但是,这是一个由WinSCP程序集生成和捕获的内部异常.我只注意到它,因为我已经将Visual Studio配置为在每次异常抛出时停止.如果我关闭此设置(或继续通过此设置和一些其他内部IOExceptions),SFTP连接将正确打开.
| 归档时间: |
|
| 查看次数: |
1674 次 |
| 最近记录: |