2 * psftp.h: interface between psftp.c / scp.c and each
\r
3 * platform-specific SFTP module.
\r
6 #ifndef PUTTY_PSFTP_H
\r
7 #define PUTTY_PSFTP_H
\r
10 * psftp_getcwd returns the local current directory. The returned
\r
11 * string must be freed by the caller.
\r
13 char *psftp_getcwd(void);
\r
16 * psftp_lcd changes the local current directory. The return value
\r
17 * is NULL on success, or else an error message which must be freed
\r
20 char *psftp_lcd(char *newdir);
\r
23 * Retrieve file times on a local file. Must return two unsigned
\r
24 * longs in POSIX time_t format.
\r
26 void get_file_times(char *filename, unsigned long *mtime,
\r
27 unsigned long *atime);
\r
30 * One iteration of the PSFTP event loop: wait for network data and
\r
33 int ssh_sftp_loop_iteration(void);
\r
36 * The main program in psftp.c. Called from main() in the platform-
\r
37 * specific code, after doing any platform-specific initialisation.
\r
39 int psftp_main(int argc, char *argv[]);
\r
42 * These functions are used by PSCP to transmit progress updates
\r
43 * and error information to a GUI window managing it. This will
\r
44 * probably only ever be supported on Windows, so these functions
\r
45 * can safely be stubs on all other platforms.
\r
47 void gui_update_stats(char *name, unsigned long size,
\r
48 int percentage, unsigned long elapsed,
\r
49 unsigned long done, unsigned long eta,
\r
50 unsigned long ratebs);
\r
51 void gui_send_errcount(int list, int errs);
\r
52 void gui_send_char(int is_stderr, int c);
\r
53 void gui_enable(char *arg);
\r
56 * It's likely that a given platform's implementation of file
\r
57 * transfer utilities is going to want to do things with them that
\r
58 * aren't present in stdio. Hence we supply an alternative
\r
59 * abstraction for file access functions.
\r
61 * This abstraction tells you the size and access times when you
\r
62 * open an existing file (platforms may choose the meaning of the
\r
63 * file times if it's not clear; whatever they choose will be what
\r
64 * PSCP sends to the server as mtime and atime), and lets you set
\r
65 * the times when saving a new file.
\r
67 * On the other hand, the abstraction is pretty simple: it supports
\r
68 * only opening a file and reading it, or creating a file and
\r
69 * writing it. (FIXME: to use this in PSFTP it will also need to
\r
70 * support seeking to a starting point for restarted transfers.)
\r
71 * None of this read-and-write, seeking-back-and-forth stuff.
\r
73 typedef struct RFile RFile;
\r
74 typedef struct WFile WFile;
\r
75 /* Output params size, mtime and atime can all be NULL if desired */
\r
76 RFile *open_existing_file(char *name, unsigned long *size,
\r
77 unsigned long *mtime, unsigned long *atime);
\r
78 /* Returns <0 on error, 0 on eof, or number of bytes read, as usual */
\r
79 int read_from_file(RFile *f, void *buffer, int length);
\r
80 /* Closes and frees the RFile */
\r
81 void close_rfile(RFile *f);
\r
82 WFile *open_new_file(char *name);
\r
83 /* Returns <0 on error, 0 on eof, or number of bytes written, as usual */
\r
84 int write_to_file(WFile *f, void *buffer, int length);
\r
85 void set_file_times(WFile *f, unsigned long mtime, unsigned long atime);
\r
86 /* Closes and frees the WFile */
\r
87 void close_wfile(WFile *f);
\r
90 * Determine the type of a file: nonexistent, file, directory or
\r
91 * weird. `weird' covers anything else - named pipes, Unix sockets,
\r
92 * device files, fish, badgers, you name it. Things marked `weird'
\r
93 * will be skipped over in recursive file transfers, so the only
\r
94 * real reason for not lumping them in with `nonexistent' is that
\r
95 * it allows a slightly more sane error message.
\r
98 FILE_TYPE_NONEXISTENT, FILE_TYPE_FILE, FILE_TYPE_DIRECTORY, FILE_TYPE_WEIRD
\r
100 int file_type(char *name);
\r
103 * Read all the file names out of a directory.
\r
105 typedef struct DirHandle DirHandle;
\r
106 DirHandle *open_directory(char *name);
\r
107 /* The string returned from this will need freeing if not NULL */
\r
108 char *read_filename(DirHandle *dir);
\r
109 void close_directory(DirHandle *dir);
\r
112 * Test a filespec to see whether it's a local wildcard or not.
\r
115 * - WCTYPE_WILDCARD (this is a wildcard).
\r
116 * - WCTYPE_FILENAME (this is a single file name).
\r
117 * - WCTYPE_NONEXISTENT (whichever it was, nothing of that name exists).
\r
119 * Some platforms may choose not to support local wildcards when
\r
120 * they come from the command line; in this case they simply never
\r
121 * return WCTYPE_WILDCARD, but still test the file's existence.
\r
122 * (However, all platforms will probably want to support wildcards
\r
123 * inside the PSFTP CLI.)
\r
126 WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD
\r
128 int test_wildcard(char *name, int cmdline);
\r
131 * Actually return matching file names for a local wildcard.
\r
133 typedef struct WildcardMatcher WildcardMatcher;
\r
134 WildcardMatcher *begin_wildcard_matching(char *name);
\r
135 /* The string returned from this will need freeing if not NULL */
\r
136 char *wildcard_get_filename(WildcardMatcher *dir);
\r
137 void finish_wildcard_matching(WildcardMatcher *dir);
\r
140 * Create a directory. Returns 0 on error, !=0 on success.
\r
142 int create_directory(char *name);
\r
145 * Concatenate a directory name and a file name. The way this is
\r
146 * done will depend on the OS.
\r
148 char *dir_file_cat(char *dir, char *file);
\r
150 #endif /* PUTTY_PSFTP_H */
\r