gpt4 book ai didi

c# - WinSCP SFTP - .tmp 进程无法访问文件

转载 作者:太空宇宙 更新时间:2023-11-03 18:28:37 24 4
gpt4 key购买 nike

我正在尝试使用以下代码上传文件,但出现以下错误。

一些注意事项:我使用的是 Windows 7。使用 CrushFTP SFTP 服务器,能够使用 FileZilla 和 WinSCP 客户端连接,但通过代码它是噩梦。

错误/异常:

A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file 'C:\Users\xxxxxxx\AppData\Local\Temp\wscp0D64.036B20B7.tmp' because it is being used by another process.

我的连接代码在下面

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
}

最佳答案

我也遇到过这个异常。对我来说,它是在调用 session.Open(...) 时生成的。

但是,这是由 WinSCP 程序集生成和捕获的内部异常。我只注意到它是因为我已将 Visual Studio 配置为在每次抛出异常时停止。如果我关闭此设置(或继续解决此问题和一些其他内部 IOException),SFTP 连接将正确打开。

关于c# - WinSCP SFTP - .tmp 进程无法访问文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28027761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com