Retrieve Date Modified of Remote Files (SFTP)

Hi,

Currently, I am trying to retrieve a file from a SFTP. The only way I can grab a unique file is by the “date modified” of the file. When I use the “File Meta Info” on local files, i have no issue. When I use “File Meta Info” after “List Remote Files” all i get are the red question marks since the file path can not resolve.

If i download the files local, then the date modified will change.

Any ideas?

EDIT: I solved this issue by extracting the date out of the file name, then doing a datetime difference to find the correct value. From there i took that file name and created the file path to it and passed that into the Download node.

No ideas, but I can confirm that the “File Meta Info” doesn’t seem to work when using the FTP connection as well (as opposed to SFTP described in previous post).

EDIT: I guess this kind of makes sense since there is no FTP or SFTP connector that feeds into this node. I think what we are looking for is a “Remote File Meta Info” node – which as of today doesn’t exist. So I think we are out of luck here.

1 Like

I was hoping going SSH Connection -> List Remote Files -> File Meta Info would work but it doesn’t.

Can you use FTPS (FTP over SSL) instead of SFTP? If so I might have some python code that you could use to get the modification date.

1 Like

Are you able to access the files with a URL? If so, you could try this in a Java Snippet:

String lastMod, eTag;
try{
	URL url = new URL(c_URL);
	HttpURLConnection conn=(HttpURLConnection)url.openConnection();
	lastMod = conn.getHeaderField("Last-modified");
	eTag=conn.getHeaderField("ETag");
} catch (Exception e) {
	NodeLogger.getLogger(getClass()).warn(e.getClass());
	NodeLogger.getLogger(getClass()).warn(e.getMessage());
	lastMod=null;
	eTag=null;
}

		
out_LastModified = lastMod;
out_ETag = eTag;
out_DateOldformat = null;
try{
	out_DateOldformat = sdf.parse(lastMod);
} catch (ParseException e){
	//
}

configured as shown:

For example, an input table containing the URL http://ftp.fau.de/eclipse/tools/buckminster/products/director_latest.zip gives the following output:

Steve

1 Like

Hi!

As @joshuahoran pointed out File Meta Info node is not a Remote File Meta Info node so that is way it is not working :slight_smile:

Br,
Ivan

Im not 100% i can since it is a SFTP. I will play with it and see if I can.

See post edit for solution.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.