【发布时间】:2019-06-04 14:33:32
【问题描述】:
我在网络作业中将文件从存储库移动到另一个存储库时遇到了一些问题。
我使用命令_session.MoveFile("mypathsource","mypathdestination")。
我的网络作业每 10 分钟触发一次。
当我部署我的网络作业时,它会移动文件,但在我的网络作业迭代几次后,它不会移动文件。它没有抛出任何异常。它只是不移动文件。
我已将 NuGet 包 WinSCP 更新到版本 5.15.2。我使用 .Net 框架 4.6.1。
public void SendFileToArchive(string fileName)
{
_log.DebugFormat("Deleting file on local path.");
File.Delete($"{_config.LocalPath}\\{fileName}");
if (!_session.Opened)
{
_log.DebugFormat("Session is closed -> Open it.");
this.OpenSession();
}
_log.DebugFormat("Move file.");
_session.MoveFile($"{fileName}", "Archive/" + fileName);
if (_session.FileExists(fileName))
{
_log.Error("File hasn't be moved");
}
}
private void OpenSession()
{
// Configurer les options de session
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = _config.FtpUrl,
UserName = _config.FtpLogin,
Password = _config.FtpPwd,
SshHostKeyFingerprint = _config.SshHostKeyFingerprint,
};
sessionOptions.AddRawSettings("ProxyPort", "0");
_session = new Session();
// Connecter
_session.Open(sessionOptions);
}
我希望文件被移动,或者至少该进程会引发异常。 有谁知道我做错了什么?
我可以在移动它之前尝试检查目标文件是否存在,但在我的用例中,如果这是原因,我会非常惊讶。因为我在出错后手动检查并且文件只存在于源路径中。
对于 openSession,我没有向您发送所有代码,但我在构造函数中调用该方法(在我的 webjob 中仅使用一次)或者当我在 move 方法中检查会话是否关闭时(我添加了该部分当我看到移动部分不起作用时检查连接的状态。
当然,当我完成所有过程时,我会调用一个 dispose 方法:
public void DisposeSession()
{
if (this._session.Opened)
{
this._session.Close();
}
this._session.Dispose();
}
这是日志:
. 2019-06-05 15:21:21.420 Listing file "FILETOMOVE_20190524_010139.json".
> 2019-06-05 15:21:21.420 Type: SSH_FXP_LSTAT, Size: 44, Number: 5639
< 2019-06-05 15:21:21.420 Type: SSH_FXP_STATUS, Size: 26, Number: 5380
. 2019-06-05 15:21:21.420 Discarding reserved response
< 2019-06-05 15:21:21.420 Type: SSH_FXP_ATTRS, Size: 54, Number: 5639
. 2019-06-05 15:21:21.420 FILETOMOVE_20190524_010139.json;-;1203;2019-05-23T23:01:40.000Z;3;"root" [0];"root" [0];rwxrwxrwx;1
< 2019-06-05 15:21:21.420 Script: -rwxrwxrwx 0 root root 1203 May 23 23:01:40 2019 FILETOMOVE_20190524_010139.json
> 2019-06-05 15:21:21.482 Script: stat -- "Archive/FILETOMOVE_20190524_010139.json"
. 2019-06-05 15:21:21.482 Listing file "Archive/FILETOMOVE_20190524_010139.json".
> 2019-06-05 15:21:21.482 Type: SSH_FXP_LSTAT, Size: 52, Number: 5895
< 2019-06-05 15:21:21.482 Type: SSH_FXP_ATTRS, Size: 54, Number: 5895
. 2019-06-05 15:21:21.482 FILETOMOVE_20190524_010139.json;-;1203;2019-05-23T23:01:40.000Z;3;"root" [0];"root" [0];rwxrwxrwx;1
< 2019-06-05 15:21:21.482 Script: -rwxrwxrwx 0 root root 1203 May 23 23:01:40 2019 FILETOMOVE_20190524_010139.json
> 2019-06-05 15:21:21.561 Script: mv "FILETOMOVE_20190524_010139.json" "Archive/FILETOMOVE_20190524_010139.json"
. 2019-06-05 15:21:21.561 Listing file "FILETOMOVE_20190524_010139.json".
> 2019-06-05 15:21:21.561 Type: SSH_FXP_LSTAT, Size: 44, Number: 6151
< 2019-06-05 15:21:21.577 Type: SSH_FXP_ATTRS, Size: 54, Number: 6151
. 2019-06-05 15:21:21.577 FILETOMOVE_20190524_010139.json;-;1203;2019-05-23T23:01:40.000Z;3;"root" [0];"root" [0];rwxrwxrwx;1
. 2019-06-05 15:21:21.577 Moving file "FILETOMOVE_20190524_010139.json" to "Archive/FILETOMOVE_20190524_010139.json".
> 2019-06-05 15:21:21.577 Type: SSH_FXP_RENAME, Size: 87, Number: 6418
< 2019-06-05 15:21:21.577 Type: SSH_FXP_STATUS, Size: 26, Number: 6418
< 2019-06-05 15:21:21.577 Status code: 0
< 2019-06-05 15:21:21.577 Script: FILETOMOVE_20190524_010139.json
> 2019-06-05 15:21:21.624 Script: stat -- "FILETOMOVE_20190524_010139.json"
. 2019-06-05 15:21:21.624 Listing file "FILETOMOVE_20190524_010139.json".
> 2019-06-05 15:21:21.624 Type: SSH_FXP_LSTAT, Size: 44, Number: 6663
< 2019-06-05 15:21:21.624 Type: SSH_FXP_ATTRS, Size: 54, Number: 6663
. 2019-06-05 15:21:21.624 FILETOMOVE_20190524_010139.json;-;1203;2019-05-23T23:01:40.000Z;3;"root" [0];"root" [0];rwxrwxrwx;1
< 2019-06-05 15:21:21.624 Script: -rwxrwxrwx 0 root root 1203 May 23 23:01:40 2019 FILETOMOVE_20190524_010139.json
有帮助吗?
【问题讨论】:
-
请提供会话日志文件! (
Session.SessionLogPath) -
不,我要求提供会话日志。
-
好的,抱歉。当问题再次出现时,我会尝试找回它。
标签: c# sftp azure-webjobs winscp winscp-net