You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
5.8 KiB
150 lines
5.8 KiB
15 years ago
|
/***************************************************************************
|
||
|
sftpProtocol.h - description
|
||
|
-------------------
|
||
|
begin : Sat Jun 30 20:08:47 CDT 2001
|
||
|
copyright : (C) 2001 by Lucas Fisher
|
||
|
email : ljfisher@purdue.edu
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
12 years ago
|
#ifndef __tdeio_sftp_h__
|
||
|
#define __tdeio_sftp_h__
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqstring.h>
|
||
|
#include <tqcstring.h>
|
||
|
#include <tqobject.h>
|
||
15 years ago
|
|
||
|
#include <kurl.h>
|
||
12 years ago
|
#include <tdeio/global.h>
|
||
|
#include <tdeio/slavebase.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
|
||
|
#include "process.h"
|
||
|
#include "sftpfileattr.h"
|
||
|
#include "ksshprocess.h"
|
||
|
|
||
|
#define KIO_SFTP_DB 7120
|
||
|
|
||
|
|
||
12 years ago
|
class sftpProtocol : public TDEIO::SlaveBase
|
||
15 years ago
|
{
|
||
|
|
||
|
public:
|
||
15 years ago
|
sftpProtocol(const TQCString &pool_socket, const TQCString &app_socket);
|
||
15 years ago
|
virtual ~sftpProtocol();
|
||
15 years ago
|
virtual void setHost(const TQString& h, int port, const TQString& user, const TQString& pass);
|
||
15 years ago
|
virtual void get(const KURL& url);
|
||
|
virtual void listDir(const KURL& url) ;
|
||
|
virtual void mimetype(const KURL& url);
|
||
|
virtual void stat(const KURL& url);
|
||
|
virtual void copy(const KURL &src, const KURL &dest, int permissions, bool overwrite);
|
||
|
virtual void put(const KURL& url, int permissions, bool overwrite, bool resume);
|
||
|
virtual void closeConnection();
|
||
|
virtual void slave_status();
|
||
|
virtual void del(const KURL &url, bool isfile);
|
||
|
virtual void chmod(const KURL& url, int permissions);
|
||
15 years ago
|
virtual void symlink(const TQString& target, const KURL& dest, bool overwrite);
|
||
15 years ago
|
virtual void rename(const KURL& src, const KURL& dest, bool overwrite);
|
||
|
virtual void mkdir(const KURL&url, int permissions);
|
||
|
virtual void openConnection();
|
||
|
|
||
|
private: // Private variables
|
||
|
/** True if ioslave is connected to sftp server. */
|
||
|
bool mConnected;
|
||
|
|
||
|
/** Host we are connected to. */
|
||
15 years ago
|
TQString mHost;
|
||
15 years ago
|
|
||
|
/** Port we are connected to. */
|
||
|
int mPort;
|
||
|
|
||
|
/** Ssh process to which we send the sftp packets. */
|
||
|
KSshProcess ssh;
|
||
|
|
||
|
/** Username to use when connecting */
|
||
15 years ago
|
TQString mUsername;
|
||
15 years ago
|
|
||
|
/** User's password */
|
||
15 years ago
|
TQString mPassword;
|
||
15 years ago
|
|
||
|
/** Message id of the last sftp packet we sent. */
|
||
|
unsigned int mMsgId;
|
||
|
|
||
|
/** Type of packet we are expecting to receive next. */
|
||
|
unsigned char mExpected;
|
||
|
|
||
|
/** Version of the sftp protocol we are using. */
|
||
|
int sftpVersion;
|
||
|
|
||
14 years ago
|
struct Status
|
||
15 years ago
|
{
|
||
|
int code;
|
||
12 years ago
|
TDEIO::filesize_t size;
|
||
15 years ago
|
TQString text;
|
||
15 years ago
|
};
|
||
|
|
||
|
private: // private methods
|
||
15 years ago
|
bool getPacket(TQByteArray& msg);
|
||
15 years ago
|
|
||
|
/* Type is a sftp packet type found in .sftp.h'.
|
||
|
* Example: SSH2_FXP_READLINK, SSH2_FXP_RENAME, etc.
|
||
|
*
|
||
|
* Returns true if the type is supported by the sftp protocol
|
||
|
* version negotiated by the client and server (sftpVersion).
|
||
|
*/
|
||
|
bool isSupportedOperation(int type);
|
||
|
/** Used to have the server canonicalize any given path name to an absolute path.
|
||
|
This is useful for converting path names containing ".." components or relative
|
||
|
pathnames without a leading slash into absolute paths.
|
||
|
Returns the canonicalized url. */
|
||
|
int sftpRealPath(const KURL& url, KURL& newUrl);
|
||
|
|
||
|
/** Send an sftp packet to stdin of the ssh process. */
|
||
15 years ago
|
bool putPacket(TQByteArray& p);
|
||
15 years ago
|
/** Process SSH_FXP_STATUS packets. */
|
||
14 years ago
|
void processStatus(TQ_UINT8, const TQString& message = TQString::null);
|
||
15 years ago
|
/** Process SSH_FXP_STATUS packes and return the result. */
|
||
14 years ago
|
Status doProcessStatus(TQ_UINT8, const TQString& message = TQString::null);
|
||
15 years ago
|
/** Opens a directory handle for url.path. Returns true if succeeds. */
|
||
15 years ago
|
int sftpOpenDirectory(const KURL& url, TQByteArray& handle);
|
||
15 years ago
|
/** Closes a directory or file handle. */
|
||
15 years ago
|
int sftpClose(const TQByteArray& handle);
|
||
15 years ago
|
/** Send a sftp command to rename a file or directoy. */
|
||
|
int sftpRename(const KURL& src, const KURL& dest);
|
||
|
/** Set a files attributes. */
|
||
|
int sftpSetStat(const KURL& url, const sftpFileAttr& attr);
|
||
|
/** Sends a sftp command to remove a file or directory. */
|
||
|
int sftpRemove(const KURL& url, bool isfile);
|
||
|
/** Creates a symlink named dest to target. */
|
||
15 years ago
|
int sftpSymLink(const TQString& target, const KURL& dest);
|
||
15 years ago
|
/** Get directory listings. */
|
||
15 years ago
|
int sftpReadDir(const TQByteArray& handle, const KURL& url);
|
||
15 years ago
|
/** Retrieves the destination of a link. */
|
||
15 years ago
|
int sftpReadLink(const KURL& url, TQString& target);
|
||
15 years ago
|
/** Stats a file. */
|
||
|
int sftpStat(const KURL& url, sftpFileAttr& attr);
|
||
|
/** No descriptions */
|
||
14 years ago
|
int sftpOpen(const KURL& url, const TQ_UINT32 pflags, const sftpFileAttr& attr, TQByteArray& handle);
|
||
15 years ago
|
/** No descriptions */
|
||
12 years ago
|
int sftpRead(const TQByteArray& handle, TDEIO::filesize_t offset, TQ_UINT32 len, TQByteArray& data);
|
||
15 years ago
|
/** No descriptions */
|
||
12 years ago
|
int sftpWrite(const TQByteArray& handle, TDEIO::filesize_t offset, const TQByteArray& data);
|
||
15 years ago
|
|
||
|
/** Performs faster upload when the source is a local file... */
|
||
|
void sftpCopyPut(const KURL& src, const KURL& dest, int mode, bool overwrite);
|
||
|
/** Performs faster download when the destination is a local file... */
|
||
|
void sftpCopyGet(const KURL& dest, const KURL& src, int mode, bool overwrite);
|
||
|
|
||
|
/** */
|
||
12 years ago
|
Status sftpGet( const KURL& src, TDEIO::filesize_t offset = 0, int fd = -1);
|
||
15 years ago
|
void sftpPut( const KURL& dest, int permissions, bool resume, bool overwrite, int fd = -1);
|
||
|
};
|
||
|
#endif
|