Implement the `close' command, which terminates an SFTP session but
[u/mdw/putty] / psftp.h
CommitLineData
876eefd4 1/*
2 * psftp.h: interface between psftp.c / scp.c and each
3 * platform-specific SFTP module.
4 */
5
6#ifndef PUTTY_PSFTP_H
7#define PUTTY_PSFTP_H
8
9/*
10 * psftp_getcwd returns the local current directory. The returned
11 * string must be freed by the caller.
12 */
13char *psftp_getcwd(void);
14
15/*
16 * psftp_lcd changes the local current directory. The return value
17 * is NULL on success, or else an error message which must be freed
18 * by the caller.
19 */
20char *psftp_lcd(char *newdir);
21
22/*
23 * Retrieve file times on a local file. Must return two unsigned
24 * longs in POSIX time_t format.
25 */
26void get_file_times(char *filename, unsigned long *mtime,
27 unsigned long *atime);
28
29/*
30 * One iteration of the PSFTP event loop: wait for network data and
31 * process it, once.
32 */
33int ssh_sftp_loop_iteration(void);
34
35/*
39934deb 36 * Read a command line for PSFTP from standard input. Caller must
37 * free.
65857773 38 *
39 * If `backend_required' is TRUE, should also listen for activity
40 * at the backend (rekeys, clientalives, unexpected closures etc)
41 * and respond as necessary, and if the backend closes it should
42 * treat this as a failure condition. If `backend_required' is
43 * FALSE, a back end is not (intentionally) active at all (e.g.
44 * psftp before an `open' command).
39934deb 45 */
65857773 46char *ssh_sftp_get_cmdline(char *prompt, int backend_required);
39934deb 47
48/*
876eefd4 49 * The main program in psftp.c. Called from main() in the platform-
50 * specific code, after doing any platform-specific initialisation.
51 */
52int psftp_main(int argc, char *argv[]);
53
54/*
55 * These functions are used by PSCP to transmit progress updates
56 * and error information to a GUI window managing it. This will
57 * probably only ever be supported on Windows, so these functions
58 * can safely be stubs on all other platforms.
59 */
60void gui_update_stats(char *name, unsigned long size,
61 int percentage, unsigned long elapsed,
62 unsigned long done, unsigned long eta,
63 unsigned long ratebs);
64void gui_send_errcount(int list, int errs);
65void gui_send_char(int is_stderr, int c);
66void gui_enable(char *arg);
67
68/*
69 * It's likely that a given platform's implementation of file
70 * transfer utilities is going to want to do things with them that
71 * aren't present in stdio. Hence we supply an alternative
72 * abstraction for file access functions.
73 *
74 * This abstraction tells you the size and access times when you
75 * open an existing file (platforms may choose the meaning of the
76 * file times if it's not clear; whatever they choose will be what
77 * PSCP sends to the server as mtime and atime), and lets you set
78 * the times when saving a new file.
79 *
80 * On the other hand, the abstraction is pretty simple: it supports
81 * only opening a file and reading it, or creating a file and
82 * writing it. (FIXME: to use this in PSFTP it will also need to
83 * support seeking to a starting point for restarted transfers.)
84 * None of this read-and-write, seeking-back-and-forth stuff.
85 */
86typedef struct RFile RFile;
87typedef struct WFile WFile;
88/* Output params size, mtime and atime can all be NULL if desired */
89RFile *open_existing_file(char *name, unsigned long *size,
90 unsigned long *mtime, unsigned long *atime);
91/* Returns <0 on error, 0 on eof, or number of bytes read, as usual */
92int read_from_file(RFile *f, void *buffer, int length);
93/* Closes and frees the RFile */
94void close_rfile(RFile *f);
95WFile *open_new_file(char *name);
96/* Returns <0 on error, 0 on eof, or number of bytes written, as usual */
97int write_to_file(WFile *f, void *buffer, int length);
98void set_file_times(WFile *f, unsigned long mtime, unsigned long atime);
99/* Closes and frees the WFile */
100void close_wfile(WFile *f);
101
102/*
103 * Determine the type of a file: nonexistent, file, directory or
104 * weird. `weird' covers anything else - named pipes, Unix sockets,
105 * device files, fish, badgers, you name it. Things marked `weird'
106 * will be skipped over in recursive file transfers, so the only
107 * real reason for not lumping them in with `nonexistent' is that
108 * it allows a slightly more sane error message.
109 */
110enum {
111 FILE_TYPE_NONEXISTENT, FILE_TYPE_FILE, FILE_TYPE_DIRECTORY, FILE_TYPE_WEIRD
112};
113int file_type(char *name);
114
115/*
116 * Read all the file names out of a directory.
117 */
118typedef struct DirHandle DirHandle;
119DirHandle *open_directory(char *name);
120/* The string returned from this will need freeing if not NULL */
121char *read_filename(DirHandle *dir);
122void close_directory(DirHandle *dir);
123
124/*
125 * Test a filespec to see whether it's a local wildcard or not.
126 * Return values:
127 *
128 * - WCTYPE_WILDCARD (this is a wildcard).
129 * - WCTYPE_FILENAME (this is a single file name).
130 * - WCTYPE_NONEXISTENT (whichever it was, nothing of that name exists).
131 *
132 * Some platforms may choose not to support local wildcards when
133 * they come from the command line; in this case they simply never
134 * return WCTYPE_WILDCARD, but still test the file's existence.
135 * (However, all platforms will probably want to support wildcards
136 * inside the PSFTP CLI.)
137 */
138enum {
139 WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD
140};
141int test_wildcard(char *name, int cmdline);
142
143/*
144 * Actually return matching file names for a local wildcard.
145 */
146typedef struct WildcardMatcher WildcardMatcher;
147WildcardMatcher *begin_wildcard_matching(char *name);
148/* The string returned from this will need freeing if not NULL */
149char *wildcard_get_filename(WildcardMatcher *dir);
150void finish_wildcard_matching(WildcardMatcher *dir);
151
152/*
153 * Create a directory. Returns 0 on error, !=0 on success.
154 */
155int create_directory(char *name);
156
157/*
158 * Concatenate a directory name and a file name. The way this is
159 * done will depend on the OS.
160 */
161char *dir_file_cat(char *dir, char *file);
162
163#endif /* PUTTY_PSFTP_H */