Hello, I want to get a list of files on FTP server giving a file pattern. For example I want to get a list of files matching following pattern: /matmaster/MATMASTER_*.CSV
Why do I want this? Because it is not allowed for us to make any file movement on the remote server. So we have to check none-downloaded files on the FTP and download if exists.
Is there any dotnet solution for this?
Cem Karaer @ Pargesoft
Dynamics NAV Developer since 2005
0
Answers
Hope this helps.
"FtpWebReques" is System.Net.FtpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
FtpWebResponse is System.Net.FtpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
--
LOCAL ListFTPFiles(SiteAddress : Text[250];Username : Text[30];PWD : Text[30];Path : Text)
FileCount := 0;
FilesToGet.RESET;
FilesToGet.DELETEALL;
FtpWebRequest := FtpWebRequest.Create('ftp://' + SiteAddress + '/' + Path);
FtpWebRequest.Credentials := NetworkCredential.NetworkCredential(Username, PWD);
FtpWebRequest.Method := 'NLST';
FtpWebRequest.KeepAlive := TRUE;
FtpWebRequest.UseBinary := TRUE;
FtpWebResponse := FtpWebRequest.GetResponse;
Stream := FtpWebResponse.GetResponseStream;
StreamReader := StreamReader.StreamReader(Stream);
WHILE NOT (StreamReader.EndOfStream) DO BEGIN
FileCount := FileCount + 1;
FilesToGet.INIT;
FilesToGet."Is a file" := TRUE;
FilesToGet.Name := StreamReader.ReadLine;
FilesToGet.INSERT;
END;
StreamReader.Close;
Stream.Close;
--
Dynamics NAV Developer since 2005
https://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp_fields(v=vs.110).aspx
Dynamics NAV Developer since 2005
This provides a listing of the 4 character commands needed for the above process. Not all of the commands are supported. That, I think is just trial and error. I'm thinking only the RFC 959 commands are supported, but can't say for sure.
Dynamics NAV Developer since 2005