From ac4107ceea994f028ae67b43dbe6676b9ccf2b3b Mon Sep 17 00:00:00 2001 From: tmanevik Date: Thu, 19 Mar 2015 14:00:43 +0100 Subject: Editorial updates SSH application --- lib/ssh/doc/src/ssh_sftp.xml | 224 ++++++++++++++++++++++--------------------- 1 file changed, 117 insertions(+), 107 deletions(-) (limited to 'lib/ssh/doc/src/ssh_sftp.xml') diff --git a/lib/ssh/doc/src/ssh_sftp.xml b/lib/ssh/doc/src/ssh_sftp.xml index ab111562f9..95869befb8 100644 --- a/lib/ssh/doc/src/ssh_sftp.xml +++ b/lib/ssh/doc/src/ssh_sftp.xml @@ -23,43 +23,49 @@ ssh_sftp OTP + 2005-09-22 + ssh_sftp.sgml ssh_sftp SFTP client. -

This module implements an SFTP (SSH FTP) client. SFTP is a +

This module implements an SSH FTP (SFTP) client. SFTP is a secure, encrypted file transfer service available for SSH.

- DATA TYPES -

Type definitions that are used more than once in this module - and/or abstractions to indicate the intended use of the data type: + DATA TYPES +

Type definitions that are used more than once in this module, + or abstractions to indicate the intended use of the data type, or both:

-

ssh_connection_ref() - opaque to the user - returned by ssh:connect/3

-

timeout() = infinity | integer() - in milliseconds.

+ + + ssh_connection_ref() +

Opaque to the user, returned by ssh:connect/3

+ timeout() +

= infinity | integer() in milliseconds

+
- TIMEOUTS -

If the request functions for the SFTP channel return {error, timeout} - it does not guarantee that the request did not reach the server and was - not performed, it only means that we did not receive an answer from the - server within the time that was expected.

+ Time-outs +

If the request functions for the SFTP channel return {error, timeout}, + it does not guarantee that the request never reached the server and was + not performed. It only means that no answer was received from the + server within the expected time.

- start_channel(ConnectionRef) -> - start_channel(ConnectionRef, Options) -> + start_channel(ConnectionRef) -> + start_channel(ConnectionRef, Options) -> start_channel(Host, Options) -> start_channel(Host, Port, Options) -> {ok, Pid} | {ok, Pid, ConnectionRef} | {error, Reason} - Starts a SFTP client + Starts an SFTP client. Host = string() ConnectionRef = ssh_connection_ref() @@ -69,33 +75,33 @@

If no connection reference is provided, a connection is set - up and the new connection is returned. An SSH channel process + up, and the new connection is returned. An SSH channel process is started to handle the communication with the SFTP server. - The returned pid for this process should be used as input to + The returned pid for this process is to be used as input to all other API functions in this module.

-

Options are:

+

Options:

-

The timeout is passed to the ssh_channel start function, - and defaults to infinity.

+

The time-out is passed to the ssh_channel start function, + and defaults to infinity.

-

+

Desired SFTP protocol version. - The actual version will be the minimum of + The actual version is the minimum of the desired version and the maximum supported versions by the SFTP server.

-

All other options are directly passed to +

All other options are directly passed to ssh:connect/3 or ignored if a - connection is already provided.

+ connection is already provided.

@@ -106,15 +112,15 @@ ChannelPid = pid() -

Stops an SFTP channel. Does not close the SSH connetion. +

Stops an SFTP channel. Does not close the SSH connection. Use ssh:close/1 to close it.

- read_file(ChannelPid, File) -> + read_file(ChannelPid, File) -> read_file(ChannelPid, File, Timeout) -> {ok, Data} | {error, Reason} - Read a file + Reads a file. ChannelPid = pid() File = string() @@ -128,9 +134,9 @@ - write_file(ChannelPid, File, Iolist) -> + write_file(ChannelPid, File, Iolist) -> write_file(ChannelPid, File, Iolist, Timeout) -> ok | {error, Reason} - Write a file + Writes a file. ChannelPid = pid() File = string() @@ -140,14 +146,14 @@

Writes a file to the server, like - . The file is created if - it does not exist or is owerwritten if it does.

+ . The file is created if + it does not exist. The file is overwritten if it exists.

- list_dir(ChannelPid, Path) -> + list_dir(ChannelPid, Path) -> list_dir(ChannelPid, Path, Timeout) -> {ok, Filenames} | {error, Reason} - List directory + Lists the directory. ChannelPid = pid() Path = string() @@ -162,9 +168,9 @@ - open(ChannelPid, File, Mode) -> + open(ChannelPid, File, Mode) -> open(ChannelPid, File, Mode, Timeout) -> {ok, Handle} | {error, Reason} - Open a file and return a handle + Opens a file and returns a handle. ChannelPid = pid() File = string() @@ -175,14 +181,14 @@ Reason = term() -

Opens a file on the server, and returns a handle that +

Opens a file on the server and returns a handle, which can be used for reading or writing.

- opendir(ChannelPid, Path) -> + opendir(ChannelPid, Path) -> opendir(ChannelPid, Path, Timeout) -> {ok, Handle} | {error, Reason} - Open a directory and return a handle + Opens a directory and returns a handle. ChannelPid = pid() Path = string() @@ -190,7 +196,7 @@ Reason = term() -

Opens a handle to a directory on the server, the handle +

Opens a handle to a directory on the server. The handle can be used for reading directory contents.

@@ -198,14 +204,15 @@ open_tar(ChannelPid, Path, Mode) -> open_tar(ChannelPid, Path, Mode, Timeout) -> {ok, Handle} | {error, Reason} - Opens a tar file on the server to which ChannelPid is connected and returns a handle + Opens a tar file on the server to which ChannelPid + is connected and returns a handle. ChannelPid = pid() Path = string() - Mode = [read] | [write] | [read,EncryptOpt] | [write,DecryptOpt] + Mode = [read] | [write] | [read,EncryptOpt] | [write,DecryptOpt] EncryptOpt = {crypto,{InitFun,EncryptFun,CloseFun}} DecryptOpt = {crypto,{InitFun,DecryptFun}} - InitFun = (fun() -> {ok,CryptoState}) | (fun() -> {ok,CryptoState,ChunkSize}) + InitFun = (fun() -> {ok,CryptoState}) | (fun() -> {ok,CryptoState,ChunkSize}) CryptoState = any() ChunkSize = undefined | pos_integer() EncryptFun = (fun(PlainBin,CryptoState) -> EncryptResult) @@ -219,11 +226,11 @@ Reason = term() -

Opens a handle to a tar file on the server associated with ChannelPid. The handle - can be used for remote tar creation and extraction as defined by the +

Opens a handle to a tar file on the server, associated with ChannelPid. + The handle can be used for remote tar creation and extraction, as defined by the erl_tar:init/3 function.

-

An example of writing and then reading a tar file:

+

Example of writing and then reading a tar file follows:

{ok,HandleWrite} = ssh_sftp:open_tar(ChannelPid, ?tar_file_name, [write]), ok = erl_tar:add(HandleWrite, .... ), @@ -238,25 +245,24 @@ ok = erl_tar:close(HandleRead), -

The crypto mode option is applied to the generated stream of bytes just prior to sending - them to the sftp server. This is intended for encryption but could of course be used for other +

The crypto mode option is applied to the generated stream of bytes prior to sending + them to the SFTP server. This is intended for encryption but can be used for other purposes.

The InitFun is applied once - prior to any other crypto operation. The returned CryptoState is then folded into - repeated applications of the EncryptFun or DecryptFun. The binary returned - from those Funs are sent further to the remote sftp server. Finally - if doing encryption - - the CloseFun is applied to the last piece of data. The CloseFun is + prior to any other crypto operation. The returned CryptoState is then folded into + repeated applications of the EncryptFun or DecryptFun. The binary returned + from those funs are sent further to the remote SFTP server. Finally, if doing encryption, + the CloseFun is applied to the last piece of data. The CloseFun is responsible for padding (if needed) and encryption of that last piece.

The ChunkSize defines the size of the PlainBins that EncodeFun is applied - to. If the ChunkSize is undefined the size of the PlainBins varies because - this is inteded for stream crypto while a fixed ChunkSize is intended for block crypto. It - is possible to change the ChunkSizes in the return from the EncryptFun or - DecryptFun. It is in fact possible to change the value between pos_integer() and - undefined. + to. If the ChunkSize is undefined, the size of the PlainBins varies, + because this is intended for stream crypto, whereas a fixed ChunkSize is intended for block crypto. + ChunkSizes can be changed in the return from the EncryptFun or + DecryptFun. The value can be changed between pos_integer() and undefined.

-

The write and read example above can be extended with encryption and decryption:

+

The previous write and read example can be extended with encryption and decryption as follows:

%% First three parameters depending on which crypto type we select: Key = <<"This is a 256 bit key. abcdefghi">>, @@ -307,9 +313,9 @@
- close(ChannelPid, Handle) -> + close(ChannelPid, Handle) -> close(ChannelPid, Handle, Timeout) -> ok | {error, Reason} - Close an open handle + Closes an open handle. ChannelPid = pid() Handle = term() @@ -321,11 +327,11 @@ - read(ChannelPid, Handle, Len) -> + read(ChannelPid, Handle, Len) -> read(ChannelPid, Handle, Len, Timeout) -> {ok, Data} | eof | {error, Error} - pread(ChannelPid, Handle, Position, Len) -> + pread(ChannelPid, Handle, Position, Len) -> pread(ChannelPid, Handle, Position, Len, Timeout) -> {ok, Data} | eof | {error, Error} - Read from an open file + Reads from an open file. ChannelPid = pid() Handle = term() @@ -340,8 +346,8 @@ . Returns , , or . If the file is opened with , is a binary, otherwise it is a string.

-

If the file is read past eof, only the remaining bytes - will be read and returned. If no bytes are read, +

If the file is read past eof, only the remaining bytes + are read and returned. If no bytes are read, is returned.

The function reads from a specified position, combining the and functions.

@@ -350,7 +356,7 @@ aread(ChannelPid, Handle, Len) -> {async, N} | {error, Error} apread(ChannelPid, Handle, Position, Len) -> {async, N} | {error, Error} - Read asynchronously from an open file + Reads asynchronously from an open file. ChannelPid = pid() Handle = term() @@ -361,12 +367,12 @@

Reads from an open file, without waiting for the result. If the - handle is valid, the function returns , where N + handle is valid, the function returns , where N is a term guaranteed to be unique between calls of . The actual data is sent as a message to the calling process. This message has the form , where is the result from the read, either , - or , or .

+ , or .

The function reads from a specified position, combining the and functions.

@@ -374,9 +380,9 @@ write(ChannelPid, Handle, Data) -> write(ChannelPid, Handle, Data, Timeout) -> ok | {error, Error} - pwrite(ChannelPid, Handle, Position, Data) -> ok + pwrite(ChannelPid, Handle, Position, Data) -> ok pwrite(ChannelPid, Handle, Position, Data, Timeout) -> ok | {error, Error} - Write to an open file + Writes to an open file. ChannelPid = pid() Handle = term() @@ -386,27 +392,27 @@ Reason = term() -

Writes to the file referenced by . - The file should be opened with or - flag. Returns if successful or S +

Writes to the file referenced by . + The file is to be opened with or + flag. Returns if successful or otherwise.

-

Typical error reasons are:

+

Typical error reasons:

-

The file is not opened for writing.

+

File is not opened for writing.

-

There is a no space left on the device.

+

No space is left on the device.

- awrite(ChannelPid, Handle, Data) -> ok | {error, Reason} + awrite(ChannelPid, Handle, Data) -> ok | {error, Reason} apwrite(ChannelPid, Handle, Position, Data) -> ok | {error, Reason} - Write asynchronously to an open file + Writes asynchronously to an open file. ChannelPid = pid() Handle = term() @@ -418,24 +424,25 @@

Writes to an open file, without waiting for the result. If the - handle is valid, the function returns , where N + handle is valid, the function returns , where N is a term guaranteed to be unique between calls of . The result of the operation is sent as a message to the calling process. This message has the form , where is the result from the write, either , or .

-

The writes on a specified position, combining +

writes on a specified position, combining the and operations.

- position(ChannelPid, Handle, Location) -> + position(ChannelPid, Handle, Location) -> position(ChannelPid, Handle, Location, Timeout) -> {ok, NewPosition | {error, Error} - Seek position in open file + Sets the file position of a file. ChannelPid = pid() Handle = term() - Location = Offset | {bof, Offset} | {cur, Offset} | {eof, Offset} | bof | cur | eof + Location = Offset + | {bof, Offset} | {cur, Offset} | {eof, Offset} | bof | cur | eof Offset = integer() Timeout = timeout() NewPosition = integer() @@ -465,15 +472,17 @@ -

The same as above with 0.

+

The same as eariler with 0, + that is, . +

- read_file_info(ChannelPid, Name) -> + read_file_info(ChannelPid, Name) -> read_file_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | {error, Reason} - Get information about a file + Gets information about a file. ChannelPid = pid() Name = string() @@ -484,13 +493,14 @@

Returns a record from the file specified by - or , like .

+ or , + like .

read_link_info(ChannelPid, Name) -> {ok, FileInfo} | {error, Reason} read_link_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | {error, Reason} - Get information about a symbolic link + Gets information about a symbolic link. ChannelPid = pid() Name = string() @@ -506,9 +516,9 @@ - write_file_info(ChannelPid, Name, Info) -> + write_file_info(ChannelPid, Name, Info) -> write_file_info(ChannelPid, Name, Info, Timeout) -> ok | {error, Reason} - Write information for a file + Writes information for a file. ChannelPid = pid() Name = string() @@ -522,9 +532,9 @@ - read_link(ChannelPid, Name) -> + read_link(ChannelPid, Name) -> read_link(ChannelPid, Name, Timeout) -> {ok, Target} | {error, Reason} - Read symbolic link + Reads symbolic link. ChannelPid = pid() Name = string() @@ -537,9 +547,9 @@ - make_symlink(ChannelPid, Name, Target) -> + make_symlink(ChannelPid, Name, Target) -> make_symlink(ChannelPid, Name, Target, Timeout) -> ok | {error, Reason} - Create symbolic link + Creates a symbolic link. ChannelPid = pid() Name = string() @@ -552,9 +562,9 @@ - rename(ChannelPid, OldName, NewName) -> + rename(ChannelPid, OldName, NewName) -> rename(ChannelPid, OldName, NewName, Timeout) -> ok | {error, Reason} - Rename a file + Renames a file. ChannelPid = pid() OldName = string() @@ -563,14 +573,14 @@ Reason = term() -

Renames a file named , and gives it the name - , like

+

Renames a file named and gives it the name + , like .

- delete(ChannelPid, Name) -> + delete(ChannelPid, Name) -> delete(ChannelPid, Name, Timeout) -> ok | {error, Reason} - Delete a file + Deletes a file. ChannelPid = pid() Name = string() @@ -579,13 +589,13 @@

Deletes the file specified by , like -

+ .

- make_dir(ChannelPid, Name) -> + make_dir(ChannelPid, Name) -> make_dir(ChannelPid, Name, Timeout) -> ok | {error, Reason} - Create a directory + Creates a directory. ChannelPid = pid() Name = string() @@ -593,15 +603,15 @@ Reason = term() -

Creates a directory specified by . should - be a full path to a new directory. The directory can only be +

Creates a directory specified by . + must be a full path to a new directory. The directory can only be created in an existing directory.

- del_dir(ChannelPid, Name) -> + del_dir(ChannelPid, Name) -> del_dir(ChannelPid, Name, Timeout) -> ok | {error, Reason} - Delete an empty directory + Deletes an empty directory. ChannelPid = pid() Name = string() @@ -610,7 +620,7 @@

Deletes a directory specified by . - Note that the directory must be empty before it can be successfully deleted + The directory must be empty before it can be successfully deleted.

-- cgit v1.2.3 From cc4996c9b3ad5294d3c3e6bb2435baaabec3f319 Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Wed, 22 Apr 2015 14:51:34 +0200 Subject: ssh: Align to alphabetic order --- lib/ssh/doc/src/ssh_sftp.xml | 545 ++++++++++++++++++++++++------------------- 1 file changed, 311 insertions(+), 234 deletions(-) (limited to 'lib/ssh/doc/src/ssh_sftp.xml') diff --git a/lib/ssh/doc/src/ssh_sftp.xml b/lib/ssh/doc/src/ssh_sftp.xml index 95869befb8..c2a86f3821 100644 --- a/lib/ssh/doc/src/ssh_sftp.xml +++ b/lib/ssh/doc/src/ssh_sftp.xml @@ -59,98 +59,132 @@ + + apread(ChannelPid, Handle, Position, Len) -> {async, N} | {error, Error} + ChannelPid = pid() + Handle = term() + Position = integer() + Len = integer() + N = term() + Reason = term() + +

The function reads from a specified position, + combining the and functions.

+

ssh_sftp:apread/3

+
+ + + aread(ChannelPid, Handle, Len) -> {async, N} | {error, Error} + Reads asynchronously from an open file. + + ChannelPid = pid() + Handle = term() + Position = integer() + Len = integer() + N = term() + Reason = term() + + +

Reads from an open file, without waiting for the result. If the + handle is valid, the function returns , where N + is a term guaranteed to be unique between calls of . + The actual data is sent as a message to the calling process. This + message has the form , where + is the result from the read, either , + , or .

+
+
+ - start_channel(ConnectionRef) -> - start_channel(ConnectionRef, Options) -> - start_channel(Host, Options) -> - start_channel(Host, Port, Options) -> {ok, Pid} | {ok, Pid, ConnectionRef} | - {error, Reason} - Starts an SFTP client. + apwrite(ChannelPid, Handle, Position, Data) -> ok | {error, Reason} + Writes asynchronously to an open file. - Host = string() - ConnectionRef = ssh_connection_ref() - Port = integer() - Options = [{Option, Value}] + ChannelPid = pid() + Handle = term() + Position = integer() + Len = integer() + Data = binary() + Timeout = timeout() Reason = term() -

If no connection reference is provided, a connection is set - up, and the new connection is returned. An SSH channel process - is started to handle the communication with the SFTP server. - The returned pid for this process is to be used as input to - all other API functions in this module.

+

writes on a specified position, combining + the and operations.

+

ssh_sftp:awrite/3

+
-

Options:

- - - -

The time-out is passed to the ssh_channel start function, - and defaults to infinity.

-
- - - - -

- Desired SFTP protocol version. - The actual version is the minimum of - the desired version and the maximum supported - versions by the SFTP server. -

-
-
-

All other options are directly passed to - ssh:connect/3 or ignored if a - connection is already provided.

+ + awrite(ChannelPid, Handle, Data) -> ok | {error, Reason} + Writes asynchronously to an open file. + + ChannelPid = pid() + Handle = term() + Position = integer() + Len = integer() + Data = binary() + Timeout = timeout() + Reason = term() + + +

Writes to an open file, without waiting for the result. If the + handle is valid, the function returns , where N + is a term guaranteed to be unique between calls of + . The result of the operation is sent + as a message to the calling process. This message has the form + , where is the result + from the write, either , or .

- stop_channel(ChannelPid) -> ok - Stops the SFTP client channel. + close(ChannelPid, Handle) -> + close(ChannelPid, Handle, Timeout) -> ok | {error, Reason} + Closes an open handle. ChannelPid = pid() + Handle = term() + Timeout = timeout() + Reason = term() -

Stops an SFTP channel. Does not close the SSH connection. - Use ssh:close/1 to close it.

+

Closes a handle to an open file or directory on the server.

- + - read_file(ChannelPid, File) -> - read_file(ChannelPid, File, Timeout) -> {ok, Data} | {error, Reason} - Reads a file. + delete(ChannelPid, Name) -> + delete(ChannelPid, Name, Timeout) -> ok | {error, Reason} + Deletes a file. - ChannelPid = pid() - File = string() - Data = binary() + ChannelPid = pid() + Name = string() Timeout = timeout() - Reason = term() + Reason = term() -

Reads a file from the server, and returns the data in a binary, - like .

+

Deletes the file specified by , like + .

+ - write_file(ChannelPid, File, Iolist) -> - write_file(ChannelPid, File, Iolist, Timeout) -> ok | {error, Reason} - Writes a file. + del_dir(ChannelPid, Name) -> + del_dir(ChannelPid, Name, Timeout) -> ok | {error, Reason} + Deletes an empty directory. ChannelPid = pid() - File = string() - Iolist = iolist() + Name = string() Timeout = timeout() Reason = term() -

Writes a file to the server, like - . The file is created if - it does not exist. The file is overwritten if it exists.

+

Deletes a directory specified by . + The directory must be empty before it can be successfully deleted. +

- + + list_dir(ChannelPid, Path) -> list_dir(ChannelPid, Path, Timeout) -> {ok, Filenames} | {error, Reason} Lists the directory. @@ -167,7 +201,41 @@ filenames as a list of strings.

+ + make_dir(ChannelPid, Name) -> + make_dir(ChannelPid, Name, Timeout) -> ok | {error, Reason} + Creates a directory. + + ChannelPid = pid() + Name = string() + Timeout = timeout() + Reason = term() + + +

Creates a directory specified by . + must be a full path to a new directory. The directory can only be + created in an existing directory.

+
+
+ + + make_symlink(ChannelPid, Name, Target) -> + make_symlink(ChannelPid, Name, Target, Timeout) -> ok | {error, Reason} + Creates a symbolic link. + + ChannelPid = pid() + Name = string() + Target = string() + Reason = term() + + +

Creates a symbolic link pointing to with the + name , like .

+
+
+ + open(ChannelPid, File, Mode) -> open(ChannelPid, File, Mode, Timeout) -> {ok, Handle} | {error, Reason} Opens a file and returns a handle. @@ -228,10 +296,11 @@

Opens a handle to a tar file on the server, associated with ChannelPid. The handle can be used for remote tar creation and extraction, as defined by the - erl_tar:init/3 function. + erl_tar:init/3 function.

+

Example of writing and then reading a tar file follows:

- + {ok,HandleWrite} = ssh_sftp:open_tar(ChannelPid, ?tar_file_name, [write]), ok = erl_tar:add(HandleWrite, .... ), ok = erl_tar:add(HandleWrite, .... ), @@ -263,7 +332,7 @@ DecryptFun. The value can be changed between pos_integer() and undefined.

The previous write and read example can be extended with encryption and decryption as follows:

- + %% First three parameters depending on which crypto type we select: Key = <<"This is a 256 bit key. abcdefghi">>, Ivec0 = crypto:rand_bytes(16), @@ -313,22 +382,52 @@
- close(ChannelPid, Handle) -> - close(ChannelPid, Handle, Timeout) -> ok | {error, Reason} - Closes an open handle. + position(ChannelPid, Handle, Location) -> + position(ChannelPid, Handle, Location, Timeout) -> {ok, NewPosition | {error, Error} + Sets the file position of a file. ChannelPid = pid() Handle = term() + Location = Offset + | {bof, Offset} | {cur, Offset} | {eof, Offset} | bof | cur | eof + Offset = integer() Timeout = timeout() + NewPosition = integer() Reason = term() -

Closes a handle to an open file or directory on the server.

+

Sets the file position of the file referenced by . + Returns (as an absolute offset) if + successful, otherwise . is + one of the following:

+ + + +

The same as .

+
+ + +

Absolute offset.

+
+ + +

Offset from the current position.

+
+ + +

Offset from the end of file.

+
+ + +

The same as eariler with 0, + that is, . +

+
+
+ - read(ChannelPid, Handle, Len) -> - read(ChannelPid, Handle, Len, Timeout) -> {ok, Data} | eof | {error, Error} pread(ChannelPid, Handle, Position, Len) -> pread(ChannelPid, Handle, Position, Len, Timeout) -> {ok, Data} | eof | {error, Error} Reads from an open file. @@ -342,44 +441,13 @@ Reason = term()
-

Reads bytes from the file referenced by - . Returns , , or - . If the file is opened with , - is a binary, otherwise it is a string.

-

If the file is read past eof, only the remaining bytes - are read and returned. If no bytes are read, - is returned.

-

The function reads from a specified position, - combining the and functions.

-
-
- - aread(ChannelPid, Handle, Len) -> {async, N} | {error, Error} - apread(ChannelPid, Handle, Position, Len) -> {async, N} | {error, Error} - Reads asynchronously from an open file. - - ChannelPid = pid() - Handle = term() - Position = integer() - Len = integer() - N = term() - Reason = term() - - -

Reads from an open file, without waiting for the result. If the - handle is valid, the function returns , where N - is a term guaranteed to be unique between calls of . - The actual data is sent as a message to the calling process. This - message has the form , where - is the result from the read, either , - , or .

-

The function reads from a specified position, - combining the and functions.

+

The function reads from a specified position, + combining the and functions.

+

ssh_sftp:read/4

+ - write(ChannelPid, Handle, Data) -> - write(ChannelPid, Handle, Data, Timeout) -> ok | {error, Error} pwrite(ChannelPid, Handle, Position, Data) -> ok pwrite(ChannelPid, Handle, Position, Data, Timeout) -> ok | {error, Error} Writes to an open file. @@ -392,94 +460,55 @@ Reason = term() -

Writes to the file referenced by . - The file is to be opened with or - flag. Returns if successful or - otherwise.

-

Typical error reasons:

- - - -

File is not opened for writing.

-
- - -

No space is left on the device.

-
-
+

The function writes to a specified position, + combining the and functions.

+

ssh_sftp:write/3

- - awrite(ChannelPid, Handle, Data) -> ok | {error, Reason} - apwrite(ChannelPid, Handle, Position, Data) -> ok | {error, Reason} - Writes asynchronously to an open file. + + + + read(ChannelPid, Handle, Len) -> + read(ChannelPid, Handle, Len, Timeout) -> {ok, Data} | eof | {error, Error} + Reads from an open file. ChannelPid = pid() Handle = term() Position = integer() Len = integer() - Data = binary() Timeout = timeout() + Data = string() | binary() Reason = term() -

Writes to an open file, without waiting for the result. If the - handle is valid, the function returns , where N - is a term guaranteed to be unique between calls of - . The result of the operation is sent - as a message to the calling process. This message has the form - , where is the result - from the write, either , or .

-

writes on a specified position, combining - the and operations.

+

Reads bytes from the file referenced by + . Returns , , or + . If the file is opened with , + is a binary, otherwise it is a string.

+

If the file is read past eof, only the remaining bytes + are read and returned. If no bytes are read, + is returned.

- - position(ChannelPid, Handle, Location) -> - position(ChannelPid, Handle, Location, Timeout) -> {ok, NewPosition | {error, Error} - Sets the file position of a file. + + + read_file(ChannelPid, File) -> + read_file(ChannelPid, File, Timeout) -> {ok, Data} | {error, Reason} + Reads a file. - ChannelPid = pid() - Handle = term() - Location = Offset - | {bof, Offset} | {cur, Offset} | {eof, Offset} | bof | cur | eof - Offset = integer() + ChannelPid = pid() + File = string() + Data = binary() Timeout = timeout() - NewPosition = integer() - Reason = term() + Reason = term() -

Sets the file position of the file referenced by . - Returns (as an absolute offset) if - successful, otherwise . is - one of the following:

- - - -

The same as .

-
- - -

Absolute offset.

-
- - -

Offset from the current position.

-
- - -

Offset from the end of file.

-
- - -

The same as eariler with 0, - that is, . -

-
-
+

Reads a file from the server, and returns the data in a binary, + like .

- + + read_file_info(ChannelPid, Name) -> read_file_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | {error, Reason} Gets information about a file. @@ -497,7 +526,24 @@ like .

- + + + read_link(ChannelPid, Name) -> + read_link(ChannelPid, Name, Timeout) -> {ok, Target} | {error, Reason} + Reads symbolic link. + + ChannelPid = pid() + Name = string() + Target = string() + Reason = term() + + +

Reads the link target from the symbolic link specified + by , like .

+
+
+ + read_link_info(ChannelPid, Name) -> {ok, FileInfo} | {error, Reason} read_link_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | {error, Reason} Gets information about a symbolic link. @@ -515,116 +561,147 @@ .

+ - write_file_info(ChannelPid, Name, Info) -> - write_file_info(ChannelPid, Name, Info, Timeout) -> ok | {error, Reason} - Writes information for a file. + rename(ChannelPid, OldName, NewName) -> + rename(ChannelPid, OldName, NewName, Timeout) -> ok | {error, Reason} + Renames a file. ChannelPid = pid() - Name = string() - Info = record() + OldName = string() + NewName = string() Timeout = timeout() Reason = term() -

Writes file information from a record to the - file specified by , like .

-
-
- - read_link(ChannelPid, Name) -> - read_link(ChannelPid, Name, Timeout) -> {ok, Target} | {error, Reason} - Reads symbolic link. - - ChannelPid = pid() - Name = string() - Target = string() - Reason = term() - - -

Reads the link target from the symbolic link specified - by , like .

+

Renames a file named and gives it the name + , like .

+ - make_symlink(ChannelPid, Name, Target) -> - make_symlink(ChannelPid, Name, Target, Timeout) -> ok | {error, Reason} - Creates a symbolic link. + start_channel(ConnectionRef) -> + start_channel(ConnectionRef, Options) -> + start_channel(Host, Options) -> + start_channel(Host, Port, Options) -> {ok, Pid} | {ok, Pid, ConnectionRef} | + {error, Reason} + Starts an SFTP client. - ChannelPid = pid() - Name = string() - Target = string() + Host = string() + ConnectionRef = ssh_connection_ref() + Port = integer() + Options = [{Option, Value}] Reason = term() -

Creates a symbolic link pointing to with the - name , like .

+

If no connection reference is provided, a connection is set + up, and the new connection is returned. An SSH channel process + is started to handle the communication with the SFTP server. + The returned pid for this process is to be used as input to + all other API functions in this module.

+ +

Options:

+ + + +

The time-out is passed to the ssh_channel start function, + and defaults to infinity.

+
+ + + + +

+ Desired SFTP protocol version. + The actual version is the minimum of + the desired version and the maximum supported + versions by the SFTP server. +

+
+
+

All other options are directly passed to + ssh:connect/3 or ignored if a + connection is already provided.

- - rename(ChannelPid, OldName, NewName) -> - rename(ChannelPid, OldName, NewName, Timeout) -> ok | {error, Reason} - Renames a file. + + + stop_channel(ChannelPid) -> ok + Stops the SFTP client channel. ChannelPid = pid() - OldName = string() - NewName = string() - Timeout = timeout() - Reason = term() -

Renames a file named and gives it the name - , like .

+

Stops an SFTP channel. Does not close the SSH connection. + Use ssh:close/1 to close it.

+ - delete(ChannelPid, Name) -> - delete(ChannelPid, Name, Timeout) -> ok | {error, Reason} - Deletes a file. + write_file(ChannelPid, File, Iolist) -> + write_file(ChannelPid, File, Iolist, Timeout) -> ok | {error, Reason} + Writes a file. ChannelPid = pid() - Name = string() + File = string() + Iolist = iolist() Timeout = timeout() Reason = term() -

Deletes the file specified by , like - .

+

Writes a file to the server, like + . The file is created if + it does not exist. The file is overwritten if it exists.

+ - make_dir(ChannelPid, Name) -> - make_dir(ChannelPid, Name, Timeout) -> ok | {error, Reason} - Creates a directory. + write(ChannelPid, Handle, Data) -> + write(ChannelPid, Handle, Data, Timeout) -> ok | {error, Error} + Writes to an open file. ChannelPid = pid() - Name = string() + Handle = term() + Position = integer() + Data = iolist() Timeout = timeout() Reason = term() -

Creates a directory specified by . - must be a full path to a new directory. The directory can only be - created in an existing directory.

+

Writes to the file referenced by . + The file is to be opened with or + flag. Returns if successful or + otherwise.

+

Typical error reasons:

+ + + +

File is not opened for writing.

+
+ + +

No space is left on the device.

+
+
+ - del_dir(ChannelPid, Name) -> - del_dir(ChannelPid, Name, Timeout) -> ok | {error, Reason} - Deletes an empty directory. + write_file_info(ChannelPid, Name, Info) -> + write_file_info(ChannelPid, Name, Info, Timeout) -> ok | {error, Reason} + Writes information for a file. ChannelPid = pid() Name = string() + Info = record() Timeout = timeout() Reason = term() -

Deletes a directory specified by . - The directory must be empty before it can be successfully deleted. -

+

Writes file information from a record to the + file specified by , like .

-
-- cgit v1.2.3 From f84db1b6f16075fdd91e456170615cbfebd7979b Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Wed, 22 Apr 2015 15:52:21 +0200 Subject: ssh: Add links --- lib/ssh/doc/src/ssh_sftp.xml | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'lib/ssh/doc/src/ssh_sftp.xml') diff --git a/lib/ssh/doc/src/ssh_sftp.xml b/lib/ssh/doc/src/ssh_sftp.xml index c2a86f3821..d52613c6bc 100644 --- a/lib/ssh/doc/src/ssh_sftp.xml +++ b/lib/ssh/doc/src/ssh_sftp.xml @@ -163,7 +163,7 @@

Deletes the file specified by , like - .

+ file:delete/1

@@ -231,7 +231,8 @@

Creates a symbolic link pointing to with the - name , like .

+ name , like + file:make_symlink/2

@@ -504,7 +505,8 @@

Reads a file from the server, and returns the data in a binary, - like .

+ like + file:read_file/1

@@ -523,7 +525,7 @@

Returns a record from the file specified by or , - like .

+ like file:read_file_info/2

@@ -539,7 +541,8 @@

Reads the link target from the symbolic link specified - by , like .

+ by , like + file:read_link/1

@@ -558,7 +561,7 @@

Returns a record from the symbolic link specified by or , like - .

+ file:read_link_info/2

@@ -575,7 +578,8 @@

Renames a file named and gives it the name - , like .

+ , like + file:rename/2

@@ -649,9 +653,10 @@ Reason = term() -

Writes a file to the server, like - . The file is created if - it does not exist. The file is overwritten if it exists.

+

Writes a file to the server, like file:write_file/2 The + file is created if it does not exist. The file is overwritten + if it exists.

@@ -699,7 +704,8 @@

Writes file information from a record to the - file specified by , like .

+ file specified by , like + file:write_file_info/[2,3]

-- cgit v1.2.3 From 6cedde4ae59a6e8505d7fc8ac22111a7a8b15e4c Mon Sep 17 00:00:00 2001 From: Ingela Anderton Andin Date: Wed, 22 Apr 2015 16:17:50 +0200 Subject: ssh: Move code example to Users Guide --- lib/ssh/doc/src/ssh_sftp.xml | 65 +++----------------------------------------- 1 file changed, 4 insertions(+), 61 deletions(-) (limited to 'lib/ssh/doc/src/ssh_sftp.xml') diff --git a/lib/ssh/doc/src/ssh_sftp.xml b/lib/ssh/doc/src/ssh_sftp.xml index d52613c6bc..4ed5a38de4 100644 --- a/lib/ssh/doc/src/ssh_sftp.xml +++ b/lib/ssh/doc/src/ssh_sftp.xml @@ -300,20 +300,9 @@ erl_tar:init/3 function.

-

Example of writing and then reading a tar file follows:

- - {ok,HandleWrite} = ssh_sftp:open_tar(ChannelPid, ?tar_file_name, [write]), - ok = erl_tar:add(HandleWrite, .... ), - ok = erl_tar:add(HandleWrite, .... ), - ... - ok = erl_tar:add(HandleWrite, .... ), - ok = erl_tar:close(HandleWrite), - - %% And for reading - {ok,HandleRead} = ssh_sftp:open_tar(ChannelPid, ?tar_file_name, [read]), - {ok,NameValueList} = erl_tar:extract(HandleRead,[memory]), - ok = erl_tar:close(HandleRead), - +

For code exampel see Section + SFTP Client with TAR Compression and Encryption in + the ssh Users Guide.

The crypto mode option is applied to the generated stream of bytes prior to sending them to the SFTP server. This is intended for encryption but can be used for other @@ -332,53 +321,7 @@ ChunkSizes can be changed in the return from the EncryptFun or DecryptFun. The value can be changed between pos_integer() and undefined.

-

The previous write and read example can be extended with encryption and decryption as follows:

- - %% First three parameters depending on which crypto type we select: - Key = <<"This is a 256 bit key. abcdefghi">>, - Ivec0 = crypto:rand_bytes(16), - DataSize = 1024, % DataSize rem 16 = 0 for aes_cbc - - %% Initialization of the CryptoState, in this case it is the Ivector. - InitFun = fun() -> {ok, Ivec0, DataSize} end, - - %% How to encrypt: - EncryptFun = - fun(PlainBin,Ivec) -> - EncryptedBin = crypto:block_encrypt(aes_cbc256, Key, Ivec, PlainBin), - {ok, EncryptedBin, crypto:next_iv(aes_cbc,EncryptedBin)} - end, - - %% What to do with the very last block: - CloseFun = - fun(PlainBin, Ivec) -> - EncryptedBin = crypto:block_encrypt(aes_cbc256, Key, Ivec, - pad(16,PlainBin) %% Last chunk - ), - {ok, EncryptedBin} - end, - - Cw = {InitFun,EncryptFun,CloseFun}, - {ok,HandleWrite} = ssh_sftp:open_tar(ChannelPid, ?tar_file_name, [write,{crypto,Cw}]), - ok = erl_tar:add(HandleWrite, .... ), - ok = erl_tar:add(HandleWrite, .... ), - ... - ok = erl_tar:add(HandleWrite, .... ), - ok = erl_tar:close(HandleWrite), - - %% And for decryption (in this crypto example we could use the same InitFun - %% as for encryption): - DecryptFun = - fun(EncryptedBin,Ivec) -> - PlainBin = crypto:block_decrypt(aes_cbc256, Key, Ivec, EncryptedBin), - {ok, PlainBin, crypto:next_iv(aes_cbc,EncryptedBin)} - end, - - Cr = {InitFun,DecryptFun}, - {ok,HandleRead} = ssh_sftp:open_tar(ChannelPid, ?tar_file_name, [read,{crypto,Cw}]), - {ok,NameValueList} = erl_tar:extract(HandleRead,[memory]), - ok = erl_tar:close(HandleRead), - + -- cgit v1.2.3