1
/***************************************************************************
2
sftpProtocol.h - description
4
begin : Sat Jun 30 20:08:47 CDT 2001
5
copyright : (C) 2001 by Lucas Fisher
6
email : ljfisher@purdue.edu
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
17
#ifndef __kio_sftp_h__
18
#define __kio_sftp_h__
25
#include <kio/global.h>
26
#include <kio/slavebase.h>
30
#include "sftpfileattr.h"
31
#include "ksshprocess.h"
33
#define KIO_SFTP_DB 7120
36
class sftpProtocol : public KIO::SlaveBase
40
sftpProtocol(const QCString &pool_socket, const QCString &app_socket);
41
virtual ~sftpProtocol();
42
virtual void setHost(const QString& h, int port, const QString& user, const QString& pass);
43
virtual void get(const KURL& url);
44
virtual void listDir(const KURL& url) ;
45
virtual void mimetype(const KURL& url);
46
virtual void stat(const KURL& url);
47
virtual void copy(const KURL &src, const KURL &dest, int permissions, bool overwrite);
48
virtual void put(const KURL& url, int permissions, bool overwrite, bool resume);
49
virtual void closeConnection();
50
virtual void slave_status();
51
virtual void del(const KURL &url, bool isfile);
52
virtual void chmod(const KURL& url, int permissions);
53
virtual void symlink(const QString& target, const KURL& dest, bool overwrite);
54
virtual void rename(const KURL& src, const KURL& dest, bool overwrite);
55
virtual void mkdir(const KURL&url, int permissions);
56
virtual void openConnection();
58
private: // Private variables
59
/** True if ioslave is connected to sftp server. */
62
/** Host we are connected to. */
65
/** Port we are connected to. */
68
/** Ssh process to which we send the sftp packets. */
71
/** Username to use when connecting */
74
/** User's password */
77
/** Message id of the last sftp packet we sent. */
80
/** Type of packet we are expecting to receive next. */
81
unsigned char mExpected;
83
/** Version of the sftp protocol we are using. */
93
private: // private methods
94
bool getPacket(QByteArray& msg);
96
/* Type is a sftp packet type found in .sftp.h'.
97
* Example: SSH2_FXP_READLINK, SSH2_FXP_RENAME, etc.
99
* Returns true if the type is supported by the sftp protocol
100
* version negotiated by the client and server (sftpVersion).
102
bool isSupportedOperation(int type);
103
/** Used to have the server canonicalize any given path name to an absolute path.
104
This is useful for converting path names containing ".." components or relative
105
pathnames without a leading slash into absolute paths.
106
Returns the canonicalized url. */
107
int sftpRealPath(const KURL& url, KURL& newUrl);
109
/** Send an sftp packet to stdin of the ssh process. */
110
bool putPacket(QByteArray& p);
111
/** Process SSH_FXP_STATUS packets. */
112
void processStatus(Q_UINT8, const QString& message = QString::null);
113
/** Process SSH_FXP_STATUS packes and return the result. */
114
Status doProcessStatus(Q_UINT8, const QString& message = QString::null);
115
/** Opens a directory handle for url.path. Returns true if succeeds. */
116
int sftpOpenDirectory(const KURL& url, QByteArray& handle);
117
/** Closes a directory or file handle. */
118
int sftpClose(const QByteArray& handle);
119
/** Send a sftp command to rename a file or directoy. */
120
int sftpRename(const KURL& src, const KURL& dest);
121
/** Set a files attributes. */
122
int sftpSetStat(const KURL& url, const sftpFileAttr& attr);
123
/** Sends a sftp command to remove a file or directory. */
124
int sftpRemove(const KURL& url, bool isfile);
125
/** Creates a symlink named dest to target. */
126
int sftpSymLink(const QString& target, const KURL& dest);
127
/** Get directory listings. */
128
int sftpReadDir(const QByteArray& handle, const KURL& url);
129
/** Retrieves the destination of a link. */
130
int sftpReadLink(const KURL& url, QString& target);
132
int sftpStat(const KURL& url, sftpFileAttr& attr);
133
/** No descriptions */
134
int sftpOpen(const KURL& url, const Q_UINT32 pflags, const sftpFileAttr& attr, QByteArray& handle);
135
/** No descriptions */
136
int sftpRead(const QByteArray& handle, KIO::filesize_t offset, Q_UINT32 len, QByteArray& data);
137
/** No descriptions */
138
int sftpWrite(const QByteArray& handle, KIO::filesize_t offset, const QByteArray& data);
140
/** Performs faster upload when the source is a local file... */
141
void sftpCopyPut(const KURL& src, const KURL& dest, int mode, bool overwrite);
142
/** Performs faster download when the destination is a local file... */
143
void sftpCopyGet(const KURL& dest, const KURL& src, int mode, bool overwrite);
146
Status sftpGet( const KURL& src, KIO::filesize_t offset = 0, int fd = -1);
147
void sftpPut( const KURL& dest, int permissions, bool resume, bool overwrite, int fd = -1);