我是WinSCP的新手。我面临着使远程路径变为动态的困难,因为我的FTP中的文件夹是由root/data/20160222/00(hour)/00(minute)/test.json*
此路径也始终包含多个文件。
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "192.168.1.100",
UserName = "admin",
Password = "admin",
};
string localPath = @"c:\\gatewayftp\\json";
// this path needs to take the latest date and the latest hour and minutes every day
string remotePath = "/data/20160228/2100/59"
现在我设定了固定的路径,为解决方案而努力。
答案 0 :(得分:2)
扩展Downloading the most recent file的WinSCP .NET程序集示例:
string remotePath = "/data";
// In each of three levels of hierarchy...
for (int i = 0; i < 3; i++)
{
// ... pick the last file/directory alphabetically
// (use .LastWriteTime instead of .Name to pick the latest file/directory by time)
remotePath +=
"/" +
session.ListDirectory(remotePath).Files
.OrderByDescending(file => file.Name).First().Name;
}