SFTP path normalization

369 views
Skip to first unread message

clemper

unread,
Jun 8, 2012, 3:00:33 PM6/8/12
to bots...@googlegroups.com
Hi,

My VAN provider requires that I cd to "/././POLLABLE" before getting the EDI files in our mailbox.  Unfortunately, the SFTP communication code does the following:

            self.dirpath = posixpath.normpath(posixpath.join(self.dirpath,self.channeldict['path'])

This causes the command "cd /POLLABLE" to be sent which the remote site says does not exist.  

Is there anyway to work around this issue other than implement the SFTP communication myself in a communicationscript?

Why not just cd to the exact string that is set for "path" in the channel configuration?  This seems like a bug to me.  My reasoning for considering it as a bug is that the code is assuming that the remote host uses POSIX path conventions, which may or may not be true.  

Thanks,

Chris Lemper

henk-jan ebbers

unread,
Jun 10, 2012, 12:27:03 PM6/10/12
to bots...@googlegroups.com
hi Chris,

some aspects:
1. I am trying to understand what is going on.
2. get this working for you.
3. having the best/right solution in bots.


about 2: for now, easiest is to subclass the sftp-class in communication.py in user scripting.
should be done like:
put a class in user script for this communication channel; class subclasses sftp-class
overwrite the connect() method.


about 1: I'm not sure if I understand what happens with 'cd /././POLLABLE'
seems to me "cd /POLLABLE" is right here?
any idea what the directory layout is? you can use edi filezilla to see the directory layout


about 3:
the normpath() is used to avoid problem with concentrating path names.

some VAN have proprietary implementations.
if it is indeed proprietary, the sub-classing solution is the best solution anyway.
any idea what server software they are using?



kind regards,
henk-jan

clemper

unread,
Jun 11, 2012, 11:15:09 AM6/11/12
to bots...@googlegroups.com
Thanks for your response.  I am not sure what SFTP server implementation they (GXS) are using but it definitely seems proprietary.  Obviously, "/././POLLABLE" should be an equivalent path to "/POLLABLE"; so they are not really mapping this path to an actual POSIX path on their end.  It does seem for now that subclassing sftp is the best solution.  The problem with this solution in the long run is that I have to create a separate script for each channel with the same contents, which will become somewhat of a maintenance issue.  Ideally there would be an option in the channel configuration to disable normalizing the path, or perhaps use quotes to indicate to use the path, as is.

Thanks,
Chris Lemper 

henk-jan ebbers

unread,
Jun 11, 2012, 11:35:51 AM6/11/12
to bots...@googlegroups.com


On 06/11/2012 05:15 PM, clemper wrote:
> Thanks for your response. I am not sure what SFTP server implementation they (GXS) are using but it definitely seems proprietary.
yes, GS is very very proprietary.
and old.
Used their stuff in 1989 ;-))
> Obviously, "/././POLLABLE" should be an equivalent path to "/POLLABLE"; so they are not really mapping this path to an actual POSIX path on their end. It does seem for now that subclassing sftp is
> the best solution. The problem with this solution in the long run is that I have to create a separate script for each channel with the same contents, which will become somewhat of a maintenance issue.
several solutions to this problem.
often, I use only one outbound and one inbound channel, using composite routes.
that way you only need one channel.

other solution would be to have one script with the actual implementation,

and the other files only import this, so the file is very short, eg:
from filename import GS-sftp

I hope you understand why I feel this is better done by sub-classing the existing sftp-class.
else I will end up with a zillion options in the channel, which will make it hard to understand.
options that are supported by standards should be in parameters, proprietary stuff should be in user scripting.


hope that helps,
henk-jan

ps I made I change for this which is in the bots repository (http://code.google.com/p/bots/source/browse/)
the sftp class now has a method 'set_cwd' which set the working directory.
sftp class is now more similar to existing ftp-classes.
in your case, you only need to overwrite this method.
Reply all
Reply to author
Forward
0 new messages