[erlang-questions] strangeness with sftpd opening files for write

Attila Rajmund Nohl attila.r.nohl@REDACTED
Thu Dec 27 13:22:42 CET 2012


This is the code segment we use:

open(Path0, Flags0, State) ->
    Flags = Flags0 -- [creat, excl, trunc],
    Result = file:open(Path, Flags),

I don't remember the details, but this might have something to do with
the SFTP versions. As far as I know, SFTP was never standardized in an
RFC, but there are I think 6 protocol versions out there documented in
at least 12 drafts. Different clients use different versions, that
could explain why you get different results from different clients. We
actually stick to version 3 on the server side, we had problems with
never versions.

2012/12/27 Alex Babkin <ababkin@REDACTED>:
> Hi
> I'm experimenting with using ssh:daemon using the ssh_sftpd subsystem (other
> words the standard erlang/otp sftp daemon) and i'm seeing some strange and
> inconsistent behavior:
> (all code is here: https://github.com/ababkin/hl7_pipeline)
> when i run the sftpd daemon and try to connect to it with an external sftp
> client (standard sftp cli on osx lion) to 'put' a file, it seems to try to
> open a new file for write with these modes/flags:
> [binary,write,creat,trunc], which results in error.
> I intercept these in my custom file_handler for sftpd (essentially just log
> the arguments in the open callback)
> Doing manually in erl shell:
>> Result = file:open("/tmp/da.txt", [binary, write, creat, trunc]).
> results in:
> {error,badarg}
> so it looks like file:open doesn't like 'creat' or 'trunc' flags that sftpd
> tries to pass to it
> this is from the default file_handler sftpd uses:
> open(Path, Flags, State) ->
>     {file:open(Path, Flags), State}.
> .. i.e just passes the flags as modes to file:open
> these results are further compounded with inconsistent behavior while
> running on different systems
> i've tried running sftpd on a mac (lion) and ubuntu, seeing the above
> results, but trying to run the sftpd on a DS211j (that uses marvell ARM cpu
> and a version of busybox distro and R15B01 probably somehow cross-compiled
> specifically for the ARM) is see a different behavior:
> on the DS211j, if i try to perform same steps as on above systems, the flags
> i intercept are [raw,binary,write], which writes the file fine and doesn't
> throw an error like in above cases
> Tried to run the otp testsuite, but seem to be failing on testsuite build
> step having to do with hipe
> Any insights would be welcome.
> For now i just overwrite the collection of modes/flags with
> [raw,binary,write] whenever there is 'write' present in the list, but this
> seems hacky
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list