2 * psftp.h: interface between psftp.c / scp.c and each
3 * platform-specific SFTP module.
12 * psftp_getcwd returns the local current directory. The returned
13 * string must be freed by the caller.
15 char *psftp_getcwd(void);
18 * psftp_lcd changes the local current directory. The return value
19 * is NULL on success, or else an error message which must be freed
22 char *psftp_lcd(char *newdir);
25 * Retrieve file times on a local file. Must return two unsigned
26 * longs in POSIX time_t format.
28 void get_file_times(char *filename, unsigned long *mtime,
29 unsigned long *atime);
32 * One iteration of the PSFTP event loop: wait for network data and
35 int ssh_sftp_loop_iteration(void);
38 * Read a command line for PSFTP from standard input. Caller must
41 * If `backend_required' is TRUE, should also listen for activity
42 * at the backend (rekeys, clientalives, unexpected closures etc)
43 * and respond as necessary, and if the backend closes it should
44 * treat this as a failure condition. If `backend_required' is
45 * FALSE, a back end is not (intentionally) active at all (e.g.
46 * psftp before an `open' command).
48 char *ssh_sftp_get_cmdline(const char *prompt, int backend_required);
51 * Platform-specific function called after the command line has been
52 * processed, so that any per-platform initialisation such as process
53 * ACL setup can be done.
55 void platform_psftp_post_option_setup(void);
58 * The main program in psftp.c. Called from main() in the platform-
59 * specific code, after doing any platform-specific initialisation.
61 int psftp_main(int argc, char *argv[]);
64 * These functions are used by PSCP to transmit progress updates
65 * and error information to a GUI window managing it. This will
66 * probably only ever be supported on Windows, so these functions
67 * can safely be stubs on all other platforms.
69 void gui_update_stats(const char *name, unsigned long size,
70 int percentage, unsigned long elapsed,
71 unsigned long done, unsigned long eta,
72 unsigned long ratebs);
73 void gui_send_errcount(int list, int errs);
74 void gui_send_char(int is_stderr, int c);
75 void gui_enable(const char *arg);
78 * It's likely that a given platform's implementation of file
79 * transfer utilities is going to want to do things with them that
80 * aren't present in stdio. Hence we supply an alternative
81 * abstraction for file access functions.
83 * This abstraction tells you the size and access times when you
84 * open an existing file (platforms may choose the meaning of the
85 * file times if it's not clear; whatever they choose will be what
86 * PSCP sends to the server as mtime and atime), and lets you set
87 * the times when saving a new file.
89 * On the other hand, the abstraction is pretty simple: it supports
90 * only opening a file and reading it, or creating a file and writing
91 * it. None of this read-and-write, seeking-back-and-forth stuff.
93 typedef struct RFile RFile;
94 typedef struct WFile WFile;
95 /* Output params size, perms, mtime and atime can all be NULL if
96 * desired. perms will be -1 if the OS does not support POSIX permissions. */
97 RFile *open_existing_file(const char *name, uint64 *size,
98 unsigned long *mtime, unsigned long *atime,
100 WFile *open_existing_wfile(const char *name, uint64 *size);
101 /* Returns <0 on error, 0 on eof, or number of bytes read, as usual */
102 int read_from_file(RFile *f, void *buffer, int length);
103 /* Closes and frees the RFile */
104 void close_rfile(RFile *f);
105 WFile *open_new_file(const char *name, long perms);
106 /* Returns <0 on error, 0 on eof, or number of bytes written, as usual */
107 int write_to_file(WFile *f, void *buffer, int length);
108 void set_file_times(WFile *f, unsigned long mtime, unsigned long atime);
109 /* Closes and frees the WFile */
110 void close_wfile(WFile *f);
111 /* Seek offset bytes through file */
112 enum { FROM_START, FROM_CURRENT, FROM_END };
113 int seek_file(WFile *f, uint64 offset, int whence);
114 /* Get file position */
115 uint64 get_file_posn(WFile *f);
117 * Determine the type of a file: nonexistent, file, directory or
118 * weird. `weird' covers anything else - named pipes, Unix sockets,
119 * device files, fish, badgers, you name it. Things marked `weird'
120 * will be skipped over in recursive file transfers, so the only
121 * real reason for not lumping them in with `nonexistent' is that
122 * it allows a slightly more sane error message.
125 FILE_TYPE_NONEXISTENT, FILE_TYPE_FILE, FILE_TYPE_DIRECTORY, FILE_TYPE_WEIRD
127 int file_type(const char *name);
130 * Read all the file names out of a directory.
132 typedef struct DirHandle DirHandle;
133 DirHandle *open_directory(const char *name);
134 /* The string returned from this will need freeing if not NULL */
135 char *read_filename(DirHandle *dir);
136 void close_directory(DirHandle *dir);
139 * Test a filespec to see whether it's a local wildcard or not.
142 * - WCTYPE_WILDCARD (this is a wildcard).
143 * - WCTYPE_FILENAME (this is a single file name).
144 * - WCTYPE_NONEXISTENT (whichever it was, nothing of that name exists).
146 * Some platforms may choose not to support local wildcards when
147 * they come from the command line; in this case they simply never
148 * return WCTYPE_WILDCARD, but still test the file's existence.
149 * (However, all platforms will probably want to support wildcards
150 * inside the PSFTP CLI.)
153 WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD
155 int test_wildcard(const char *name, int cmdline);
158 * Actually return matching file names for a local wildcard.
160 typedef struct WildcardMatcher WildcardMatcher;
161 WildcardMatcher *begin_wildcard_matching(const char *name);
162 /* The string returned from this will need freeing if not NULL */
163 char *wildcard_get_filename(WildcardMatcher *dir);
164 void finish_wildcard_matching(WildcardMatcher *dir);
167 * Vet a filename returned from the remote host, to ensure it isn't
168 * in some way malicious. The idea is that this function is applied
169 * to filenames returned from FXP_READDIR, which means we can panic
170 * if we see _anything_ resembling a directory separator.
172 * Returns TRUE if the filename is kosher, FALSE if dangerous.
174 int vet_filename(const char *name);
177 * Create a directory. Returns 0 on error, !=0 on success.
179 int create_directory(const char *name);
182 * Concatenate a directory name and a file name. The way this is
183 * done will depend on the OS.
185 char *dir_file_cat(const char *dir, const char *file);
188 * Return a pointer to the portion of str that comes after the last
189 * path component separator.
191 * If 'local' is false, path component separators are taken to just be
192 * '/', on the assumption that we're discussing the path syntax on the
193 * server. But if 'local' is true, the separators are whatever the
194 * local OS will treat that way - so that includes '\' and ':' on
197 * This function has the annoying strstr() property of taking a const
198 * char * and returning a char *. You should treat it as if it was a
199 * pair of overloaded functions, one mapping mutable->mutable and the
200 * other const->const :-(
202 char *stripslashes(const char *str, int local);
204 #endif /* PUTTY_PSFTP_H */