int main(int argc, char **argv) { KCmdLineArgs::init(argc,argv, "netaccesstest", 0, ki18n("netaccesstest"), 0); KApplication app; KUrl srcURL( "ftp://ftp.kde.org/pub/kde/README" ); #ifdef Q_WS_WIN KUrl tmpURL( "file://" + QDir::tempPath() + "/netaccesstest_README" ); #else KUrl tmpURL( "file:/tmp/netaccesstest_README" ); #endif for ( uint i = 0; i < 4 ; ++i ) { kDebug() << "file_copy"; KIO::Job* job = KIO::file_copy(srcURL, tmpURL, -1, KIO::Overwrite); if ( !KIO::NetAccess::synchronousRun(job, 0) ) kError() << "file_copy failed: " << KIO::NetAccess::lastErrorString() << endl; else { QFile f( tmpURL.path() ); if (!f.open(QIODevice::ReadOnly)) kFatal() << "Cannot open: " << f.fileName() << ". The error was: " << f.errorString(); else { f.close(); } } } return 0; }
int main(int argc, char **argv) { KApplication app( argc, argv, "netaccesstest", true /* it _has_ a GUI ! */); KURL srcURL( "ftp://ftp.kde.org/pub/kde/README" ); KURL tmpURL( "file:/tmp/netaccesstest_README" ); for ( uint i = 0; i < 4 ; ++i ) { kdDebug() << "file_copy" << endl; if ( !KIO::NetAccess::file_copy(srcURL, tmpURL, -1, true, false, 0) ) kdError() << "file_copy failed: " << KIO::NetAccess::lastErrorString() << endl; else { QFile f( tmpURL.path() ); if (!f.open(IO_ReadOnly)) kdFatal() << "Cannot open: " << f.name() << ". The error was: " << f.errorString() << endl; else { f.close(); } } } return 0; }