List root folder.

Advertisement

HugoMendes
Guest

List root folder.

SessionOptions sessionOptions1 = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "webserver",
UserName = "webguest",
Password = "1",
};

using (Session session = new Session())
{
// Connect
session.Open(sessionOptions1);

//List files
string remotePath = ""; <---Problem here
RemoteDirectoryInfo directoryInfo = session.ListDirectory(remotePath);

//See last file
directoryInfo.Files.OrderBy(p => p.LastWriteTime).ToArray();
string strfilename = directoryInfo.Files.First().FullName;
//Copiar o ultimo

status.Text = strfilename;
string exePath = Application.StartupPath;
exePath = exePath + "\\MyFiles\\";
tempPath = exePath + "img_1.bmp";
session.GetFiles(strfilename, tempPath,false);
...
...

If I want to enter the root folder of the ftp server what should I write in remotePath?
Also, i used directoryInfo.Files.OrderBy to order by time, is there a way to filter the files like only retrieve the *.bmp files?

Thanks

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
31,433
Location:
Prague, Czechia

Re: List root folder.

HugoMendes wrote:

If I want to enter the root folder of the ftp server what should I write in remotePath?
Login with GUI, browse to the "root" folder and check what path do you see in WinSCP panel. It would typically be /.

Also, i used directoryInfo.Files.OrderBy to order by time, is there a way to filter the files like only retrieve the *.bmp files?
There's Enumerable.Where extension method:
https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.where
Or you can use Session.EnumerateRemoteFiles instead of Session.ListDirectory. It supports filtering file by file mask.
https://winscp.net/eng/docs/library_session_enumerateremotefiles
Both approaches are covered in my answer to:
https://stackoverflow.com/q/34680848/850848
Also see
https://winscp.net/eng/docs/library_example_listing_files_matching_wildcard

Reply with quote

Advertisement

You can post new topics in this forum