/usr/share/qt3/doc/html/ftpclient-example.html is in qt3-doc 3:3.3.8-b-8ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/network/ftpclient/ftpclient.doc:5 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>An FTP client</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>An FTP client</h1>
<p>
<p> This example implements a FTP client. It uses <a href="qftp.html">QFtp</a> to perform its FTP
commands. The GUI parts are done in the Designer.
<p> <hr>
<p> The implementation of the FTP commands (ftpmainwindow.ui.h):
<p> <pre>/****************************************************************************
** $Id: qt/ftpmainwindow.ui.h 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
/****************************************************************************
**
** ui.h extension file, included from the uic-generated form implementation.
**
** The init() function is used in place of a constructor.
** The destroy() function is used in place of a destructor.
** The slots uploadFile(), downloadFile(), removeFile() and connectToHost() are
** connected with the resp. actions of the GUI.
**
*****************************************************************************/
#include <<a href="qftp-h.html">qftp.h</a>>
#include <<a href="qlineedit-h.html">qlineedit.h</a>>
#include <<a href="qspinbox-h.html">qspinbox.h</a>>
#include <<a href="qstatusbar-h.html">qstatusbar.h</a>>
#include <<a href="qmessagebox-h.html">qmessagebox.h</a>>
#include <<a href="qfiledialog-h.html">qfiledialog.h</a>>
#include <<a href="qprogressdialog-h.html">qprogressdialog.h</a>>
#include <<a href="qapplication-h.html">qapplication.h</a>>
#include "connectdialog.h"
#include "ftpviewitem.h"
void FtpMainWindow::init()
{
stateFtp = new <a href="qlabel.html">QLabel</a>( tr("Unconnected"), statusBar() );
statusBar()->addWidget( stateFtp, 0, TRUE );
ftp = new <a href="qftp.html">QFtp</a>( this );
<a name="x748"></a> connect( ftp, SIGNAL(<a href="qftp.html#commandStarted">commandStarted</a>(int)),
SLOT(ftp_commandStarted()) );
<a name="x747"></a> connect( ftp, SIGNAL(<a href="qftp.html#commandFinished">commandFinished</a>(int,bool)),
SLOT(ftp_commandFinished()) );
<a name="x753"></a> connect( ftp, SIGNAL(<a href="qftp.html#done">done</a>(bool)),
SLOT(ftp_done(bool)) );
<a name="x764"></a> connect( ftp, SIGNAL(<a href="qftp.html#stateChanged">stateChanged</a>(int)),
SLOT(ftp_stateChanged(int)) );
<a name="x757"></a> connect( ftp, SIGNAL(<a href="qftp.html#listInfo">listInfo</a>(const <a href="qurlinfo.html">QUrlInfo</a> &)),
SLOT(ftp_listInfo(const <a href="qurlinfo.html">QUrlInfo</a> &)) );
<a name="x761"></a> connect( ftp, SIGNAL(<a href="qftp.html#rawCommandReply">rawCommandReply</a>(int, const <a href="qstring.html">QString</a> &)),
SLOT(ftp_rawCommandReply(int, const <a href="qstring.html">QString</a> &)) );
}
void FtpMainWindow::destroy()
{
<a name="x763"></a> if ( ftp-><a href="qftp.html#state">state</a>() != QFtp::Unconnected )
<a name="x746"></a> ftp-><a href="qftp.html#close">close</a>();
}
void FtpMainWindow::uploadFile()
{
<a name="x741"></a> <a href="qstring.html">QString</a> fileName = QFileDialog::<a href="qfiledialog.html#getOpenFileName">getOpenFileName</a>(
<a href="qstring.html#QString-null">QString::null</a>,
QString::null,
this,
"upload file dialog",
tr("Choose a file to upload") );
<a name="x771"></a> if ( fileName.<a href="qstring.html#isNull">isNull</a>() )
return;
<a href="qfile.html">QFile</a> *file = new <a href="qfile.html">QFile</a>( fileName );
if ( !file-><a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_ReadOnly</a> ) ) {
<a name="x767"></a> QMessageBox::<a href="qmessagebox.html#critical">critical</a>( this, tr("Upload error"),
tr("Can't open file '%1' for reading.").arg(fileName) );
delete file;
return;
}
<a href="qprogressdialog.html">QProgressDialog</a> progress(
tr("Uploading file..."),
tr("Cancel"),
0,
this,
"upload progress dialog",
TRUE );
<a name="x752"></a> connect( ftp, SIGNAL(<a href="qftp.html#dataTransferProgress">dataTransferProgress</a>(int,int)),
<a name="x770"></a> &progress, SLOT(<a href="qprogressdialog.html#setProgress">setProgress</a>(int,int)) );
connect( ftp, SIGNAL(<a href="qftp.html#commandFinished">commandFinished</a>(int,bool)),
<a name="x769"></a> &progress, SLOT(<a href="qprogressdialog.html#reset">reset</a>()) );
<a name="x768"></a> connect( &progress, SIGNAL(<a href="qprogressdialog.html#cancelled">cancelled</a>()),
<a name="x744"></a> ftp, SLOT(<a href="qftp.html#abort">abort</a>()) );
<a href="qfileinfo.html">QFileInfo</a> fi( fileName );
<a name="x759"></a><a name="x743"></a> ftp-><a href="qftp.html#put">put</a>( file, fi.<a href="qfileinfo.html#fileName">fileName</a>() );
<a name="x739"></a> progress.<a href="qdialog.html#exec">exec</a>(); // ### takes a lot of time!!!
<a name="x756"></a> ftp-><a href="qftp.html#list">list</a>();
}
void FtpMainWindow::downloadFile()
{
FtpViewItem *item = (FtpViewItem*)remoteView->selectedItem();
if ( !item || item->isDir() )
return;
<a name="x742"></a> <a href="qstring.html">QString</a> fileName = QFileDialog::<a href="qfiledialog.html#getSaveFileName">getSaveFileName</a>(
<a name="x766"></a> item-><a href="qlistviewitem.html#text">text</a>(0),
QString::null,
this,
"download file dialog",
tr("Save downloaded file as") );
if ( fileName.<a href="qstring.html#isNull">isNull</a>() )
return;
// create file on the heap because it has to be valid throughout the whole
// asynchronous download operation
<a href="qfile.html">QFile</a> *file = new <a href="qfile.html">QFile</a>( fileName );
if ( !file-><a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_WriteOnly</a> ) ) {
QMessageBox::<a href="qmessagebox.html#critical">critical</a>( this, tr("Download error"),
tr("Can't open file '%1' for writing.").arg(fileName) );
delete file;
return;
}
<a href="qprogressdialog.html">QProgressDialog</a> progress(
tr("Downloading file..."),
tr("Cancel"),
0,
this,
"download progress dialog",
TRUE );
connect( ftp, SIGNAL(<a href="qftp.html#dataTransferProgress">dataTransferProgress</a>(int,int)),
&progress, SLOT(<a href="qprogressdialog.html#setProgress">setProgress</a>(int,int)) );
connect( ftp, SIGNAL(<a href="qftp.html#commandFinished">commandFinished</a>(int,bool)),
&progress, SLOT(<a href="qprogressdialog.html#reset">reset</a>()) );
connect( &progress, SIGNAL(<a href="qprogressdialog.html#cancelled">cancelled</a>()),
ftp, SLOT(<a href="qftp.html#abort">abort</a>()) );
<a name="x755"></a> ftp-><a href="qftp.html#get">get</a>( item-><a href="qlistviewitem.html#text">text</a>(0), file );
progress.<a href="qdialog.html#exec">exec</a>(); // ### takes a lot of time!!!
}
void FtpMainWindow::removeFile()
{
FtpViewItem *item = (FtpViewItem*)remoteView->selectedItem();
if ( !item || item->isDir() )
return;
<a name="x762"></a> ftp-><a href="qftp.html#remove">remove</a>( item-><a href="qlistviewitem.html#text">text</a>(0) );
ftp-><a href="qftp.html#list">list</a>();
}
void FtpMainWindow::connectToHost()
{
ConnectDialog connectDialog;
if ( connectDialog.exec() == QDialog::Rejected )
return;
remotePath->clear();
remoteView->clear();
if ( ftp-><a href="qftp.html#state">state</a>() != QFtp::Unconnected )
ftp-><a href="qftp.html#close">close</a>();
<a name="x749"></a> ftp-><a href="qftp.html#connectToHost">connectToHost</a>( connectDialog.host->text(), connectDialog.port->value() );
<a name="x758"></a> ftp-><a href="qftp.html#login">login</a>( connectDialog.username->text(), connectDialog.password->text() );
<a name="x760"></a> ftp-><a href="qftp.html#rawCommand">rawCommand</a>( "PWD" );
ftp-><a href="qftp.html#list">list</a>();
}
// This slot is connected to the QComboBox::activated() signal of the
// remotePath.
void FtpMainWindow::changePath( const <a href="qstring.html">QString</a> &newPath )
{
<a name="x745"></a> ftp-><a href="qftp.html#cd">cd</a>( newPath );
ftp-><a href="qftp.html#rawCommand">rawCommand</a>( "PWD" );
ftp-><a href="qftp.html#list">list</a>();
}
// This slot is connected to the QListView::doubleClicked() and
// QListView::returnPressed() signals of the remoteView.
void FtpMainWindow::changePathOrDownload( <a href="qlistviewitem.html">QListViewItem</a> *item )
{
if ( ((FtpViewItem*)item)->isDir() )
changePath( item-><a href="qlistviewitem.html#text">text</a>(0) );
else
downloadFile();
}
/****************************************************************************
**
** Slots connected to signals of the QFtp class
**
*****************************************************************************/
void FtpMainWindow::ftp_commandStarted()
{
<a name="x738"></a> QApplication::<a href="qapplication.html#setOverrideCursor">setOverrideCursor</a>( QCursor(Qt::WaitCursor) );
<a name="x750"></a> if ( ftp-><a href="qftp.html#currentCommand">currentCommand</a>() == QFtp::List ) {
remoteView->clear();
if ( currentFtpDir != "/" )
new FtpViewItem( remoteView, FtpViewItem::Directory, "..", "", "" );
}
}
void FtpMainWindow::ftp_commandFinished()
{
<a name="x737"></a> QApplication::<a href="qapplication.html#restoreOverrideCursor">restoreOverrideCursor</a>();
<a name="x751"></a> delete ftp-><a href="qftp.html#currentDevice">currentDevice</a>();
}
void FtpMainWindow::ftp_done( bool error )
{
if ( error ) {
<a name="x754"></a> QMessageBox::<a href="qmessagebox.html#critical">critical</a>( this, tr("FTP Error"), ftp-><a href="qftp.html#errorString">errorString</a>() );
// If we are connected, but not logged in, it is not meaningful to stay
// connected to the server since the error is a really fatal one (login
// failed).
if ( ftp-><a href="qftp.html#state">state</a>() == QFtp::Connected )
ftp-><a href="qftp.html#close">close</a>();
}
}
void FtpMainWindow::ftp_stateChanged( int state )
{
switch ( (QFtp::State)state ) {
case QFtp::Unconnected:
<a name="x765"></a> stateFtp-><a href="qlabel.html#setText">setText</a>( tr("Unconnected") );
break;
case QFtp::HostLookup:
stateFtp-><a href="qlabel.html#setText">setText</a>( tr("Host lookup") );
break;
case QFtp::Connecting:
stateFtp-><a href="qlabel.html#setText">setText</a>( tr("Connecting") );
break;
case QFtp::Connected:
stateFtp-><a href="qlabel.html#setText">setText</a>( tr("Connected") );
break;
case QFtp::LoggedIn:
stateFtp-><a href="qlabel.html#setText">setText</a>( tr("Logged in") );
break;
case QFtp::Closing:
stateFtp-><a href="qlabel.html#setText">setText</a>( tr("Closing") );
break;
}
}
void FtpMainWindow::ftp_listInfo( const <a href="qurlinfo.html">QUrlInfo</a> &i )
{
FtpViewItem::Type type;
<a name="x773"></a> if ( i.<a href="qurlinfo.html#isDir">isDir</a>() )
type = FtpViewItem::Directory;
else
type = FtpViewItem::File;
new FtpViewItem( remoteView, type,
<a name="x776"></a><a name="x775"></a><a name="x774"></a> i.<a href="qurlinfo.html#name">name</a>(), QString::number(i.<a href="qurlinfo.html#size">size</a>()), i.<a href="qurlinfo.html#lastModified">lastModified</a>().toString() );
}
void FtpMainWindow::ftp_rawCommandReply( int code, const <a href="qstring.html">QString</a> &text )
{
if ( code == 257 ) {
<a name="x772"></a> currentFtpDir = text.<a href="qstring.html#section">section</a>( '"', 1, 1 );
for ( int i = 0; i<remotePath->count(); i++ ) {
// make sure that we don't insert duplicates
if ( remotePath->text( i ) == currentFtpDir )
remotePath->removeItem( i );
}
remotePath->insertItem( currentFtpDir, 0 );
remotePath->setCurrentItem( 0 );
}
}
</pre>
<p> <hr>
<p> Main (main.cpp):
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include <<a href="qapplication-h.html">qapplication.h</a>>
#include "ftpmainwindow.h"
int main( int argc, char **argv )
{
<a href="qapplication.html">QApplication</a> a( argc, argv );
FtpMainWindow m;
<a name="x779"></a> a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &m );
m.show();
<a name="x778"></a> a.<a href="qapplication.html#processEvents">processEvents</a>();
m.connectToHost();
<a name="x777"></a> return a.<a href="qapplication.html#exec">exec</a>();
}
</pre>
<p>See also <a href="network-examples.html">Network Examples</a>.
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright © 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>
|