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

Alex Babkin ababkin@REDACTED
Thu Dec 27 00:05:17 CET 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121226/20dc3a91/attachment.htm>


More information about the erlang-questions mailing list