aboutsummaryrefslogtreecommitdiff
path: root/doc/sftp.dox
blob: 72e6237c57020dbb94755b5c08cc10097e7d96cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@page sftp Chapter 5: The SFTP subsystem
@section sftp_subsystem The SFTP subsystem

SFTP stands for "Secure File Transfer Protocol". It enables you to safely
transfer files between the local and the remote computer. It reminds a lot
of the old FTP protocol.

SFTP is a rich protocol. It lets you do over the network almost everything
that you can do with local files:
  - send files
  - modify only a portion of a file
  - receive files
  - receive only a portion of a file
  - get file owner and group
  - get file permissions
  - set file owner and group
  - set file permissions
  - remove files
  - rename files
  - create a directory
  - remove a directory
  - retrieve the list of files in a directory
  - get the target of a symbolic link
  - create symbolic links
  - get information about mounted filesystems.


@subsection sftp_section Opening and closing a SFTP session

Unlike with remote shells and remote commands, when you use the SFTP subsystem,
you don't handle directly the SSH channels. Instead, you open a "SFTP session".

The function sftp_new() creates a new SFTP session. The function sftp_init()
initializes it. The function sftp_free() deletes it.

As you see, all the SFTP-related functions start with the "sftp_" prefix
instead of the usual "ssh_" prefix. In case of a problem, you use
sftp_get_error() instead of ssh_get_error() to get the English error message.

The example below shows how to use these functions:

@code
#include <libssh/sftp.h>

int sftp_helloworld(ssh_session session)
{
  sftp_session sftp;
  int rc;

  sftp = sftp_new(session);
  if (sftp == NULL)
  {
    fprintf(stderr, "Error allocating SFTP session: %s\n", ssh_get_error(session));
    return SSH_ERROR;
  }

  rc = sftp_init(sftp);
  if (rc != SSH_OK)
  {
    fprintf(stderr, "Error initializing SFTP session: %s.\n", sftp_get_error(sftp));
    sftp_free(sftp);
    return rc;
  }

  ...

  sftp_free(sftp);
  return SSH_OK;
}
@endcode


@subsection sftp_mkdir Creating a directory

*** To be written ***


@subsection sftp_write Copying a file to the remote computer

*** To be written ***


@subsection sftp_read Reading a file from the remote computer

*** To be written ***