C++ (Qt)/* * FileSendDialog.cpp * * Created on: 20.09.2010 * Author: **** */ #include <QtCore/QSettings>#include <QtCore/QFileInfo>#include <QtCore/QDebug> #include <QtGui/QMessageBox> #include "core.h" #include "FileSendDialog.h" FileSendDialog::FileSendDialog (const QString &fileName, QWidget *parent) : QProgressDialog (parent), fileName_ (fileName){ manager = new QNetworkAccessManager (this); setWindowTitle (tr ("Send file..."));// setCancelButton( 0 ); setWindowModality (Qt::WindowModal); resize (440, 180); setStyleSheet ("background-color: #ffffff");} FileSendDialog::~FileSendDialog(){ } int FileSendDialog::exec(){ qDebug () << Q_FUNC_INFO; QFile data (fileName_); if (!data.open (QIODevice::ReadOnly)) { QMessageBox::critical (this, tr ("Send..."), tr ("Can't open %1 : %2").arg (fileName_) .arg (data.errorString())); return QDialog::Rejected; } QSettings systemprops (Core::SystemSettingsScope, "Simicon", "converterd"); const QString serveraddr = systemprops.value ("serverAddr", "192.168.2.193").toString();// QString serveraddr = "127.0.0.1"; const quint16 port = systemprops.value ("serverPort", "8080").toUInt() ; QUrl url; url.setScheme ("http"); url.setHost (serveraddr); url.setPort (port); QNetworkRequest request (url); request.setRawHeader ("Host", QString ("%1:%2").arg (serveraddr).arg (port).toUtf8()); request.setRawHeader ("Connection", "keep-alive"); request.setRawHeader ("Keep-Alive", "300"); request.setRawHeader ("User-Agent", "convertregui"); const QByteArray boundaryRegular = "---------------------------193971182219751"; request.setRawHeader ("Content-Type", "multipart/form-data; boundary=" + boundaryRegular); const QFileInfo fi (fileName_); const QByteArray head = "--" + boundaryRegular + "\r\n" + "Content-Disposition: form-data; name=\"out_of_band\"; filename=\"" + fi.fileName().toUtf8() + "\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n"; const QByteArray tail = "\r\n--" + boundaryRegular + "--\r\n" + QByteArray (10 * 1024, ' '); QNetworkReply *reply = manager->post (request, head + data.readAll () + tail); connect (reply, SIGNAL (uploadProgress (qint64, qint64)), this, SLOT (uploadProgress (qint64, qint64))); connect (reply, SIGNAL (finished()), this, SLOT (replyFinished())); setWindowTitle (tr ("Send file %1").arg (fi.fileName())); return QProgressDialog::exec();} void FileSendDialog::replyFinished(){ QNetworkReply *reply = qobject_cast <QNetworkReply*> (sender ()); Q_CHECK_PTR (reply); qDebug () << QString ("Reply finished with code %1").arg (reply->error ()); if (reply->error() != QNetworkReply::NoError) { QMessageBox::critical (this, tr ("Error..."), tr ("Network error: %1").arg (reply->errorString ())); done (QDialog::Rejected); } else { QMessageBox::information (this, QString (), tr ("File is successfully sent")); done (QDialog::Accepted); } reply->deleteLater ();} void FileSendDialog::uploadProgress (qint64 bytesSent, qint64 bytesTotal){ qDebug () << QString ("FileSendDialog::uploadProgress %1 from %2") .arg (bytesSent) .arg (bytesTotal); setRange (0, bytesTotal + 1); setValue (bytesSent);}
int FileSendDialog::exec() "FileSendDialog::uploadProgress 16384 from 246465" "FileSendDialog::uploadProgress 32768 from 246465" "FileSendDialog::uploadProgress 49152 from 246465" "FileSendDialog::uploadProgress 65536 from 246465" "FileSendDialog::uploadProgress 81920 from 246465" "FileSendDialog::uploadProgress 98304 from 246465" "FileSendDialog::uploadProgress 114688 from 246465" "FileSendDialog::uploadProgress 131072 from 246465" "FileSendDialog::uploadProgress 147456 from 246465" "FileSendDialog::uploadProgress 163840 from 246465" "FileSendDialog::uploadProgress 180224 from 246465" "FileSendDialog::uploadProgress 196608 from 246465" "FileSendDialog::uploadProgress 212992 from 246465" "FileSendDialog::uploadProgress 229376 from 246465" "FileSendDialog::uploadProgress 245760 from 246465" "FileSendDialog::uploadProgress 246465 from 246465" "FileSendDialog::uploadProgress 16384 from 246465" "FileSendDialog::uploadProgress 32768 from 246465" "FileSendDialog::uploadProgress 49152 from 246465" "FileSendDialog::uploadProgress 65536 from 246465" "FileSendDialog::uploadProgress 81920 from 246465" "FileSendDialog::uploadProgress 98304 from 246465" "FileSendDialog::uploadProgress 114688 from 246465" "FileSendDialog::uploadProgress 131072 from 246465" "FileSendDialog::uploadProgress 147456 from 246465" "FileSendDialog::uploadProgress 163840 from 246465" "FileSendDialog::uploadProgress 180224 from 246465" "FileSendDialog::uploadProgress 196608 from 246465" "FileSendDialog::uploadProgress 212992 from 246465" "FileSendDialog::uploadProgress 229376 from 246465" "FileSendDialog::uploadProgress 245760 from 246465" "FileSendDialog::uploadProgress 246465 from 246465" "FileSendDialog::uploadProgress 16384 from 246465" "FileSendDialog::uploadProgress 32768 from 246465" "FileSendDialog::uploadProgress 49152 from 246465" "FileSendDialog::uploadProgress 65536 from 246465" "FileSendDialog::uploadProgress 81920 from 246465" "FileSendDialog::uploadProgress 98304 from 246465" "FileSendDialog::uploadProgress 114688 from 246465" "FileSendDialog::uploadProgress 131072 from 246465" "FileSendDialog::uploadProgress 147456 from 246465" "FileSendDialog::uploadProgress 163840 from 246465" "FileSendDialog::uploadProgress 180224 from 246465" "FileSendDialog::uploadProgress 196608 from 246465" "FileSendDialog::uploadProgress 212992 from 246465" "FileSendDialog::uploadProgress 229376 from 246465" "FileSendDialog::uploadProgress 245760 from 246465" "FileSendDialog::uploadProgress 246465 from 246465" "Reply finished with code 2"
[root@KS0000 ~]# logreceiver 4000 | grep stimpstimp_13293: POST / HTTP/1.1stimp_13293: Host: 192.168.2.193:8080stimp_13293: Connection: keep-alivestimp_13293: Keep-Alive: 300stimp_13293: User-Agent: convertreguistimp_13293: Content-Type: multipart/form-data; boundary=---------------------7c9758f23dstimp_13293: Content-Length: 236203stimp_13293: Accept-Encoding: gzipstimp_13293: Accept-Language: ru-RU,en,*stimp_13293: -----------------------7c9758f23dstimp_13293: Content-Disposition: form-data; name="out_of_band"; filename="20120116141559.tar.log"stimp_13293: Content-Type: application/octet-streamstimp_13293: stimp_13293: stimp_13293: HTTP/1.0 200 OKstimp_13293: Connection: keep-alivestimp_13293: Content-Type: text/plain; charset=utf-8stimp_13293: stimp_13293: stimp_13293: stimp_13293: DONE!stimp_13293: stimp_13293: EXITstimp_13295: stimp_13295: POST / HTTP/1.1stimp_13295: Host: 192.168.2.193:8080stimp_13295: Connection: keep-alivestimp_13295: Keep-Alive: 300stimp_13295: User-Agent: convertreguistimp_13295: Content-Type: multipart/form-data; boundary=---------------------7c9758f23dstimp_13295: Content-Length: 236203stimp_13295: Accept-Encoding: gzipstimp_13295: Accept-Language: ru-RU,en,*stimp_13295: -----------------------7c9758f23dstimp_13295: Content-Disposition: form-data; name="out_of_band"; filename="20120116141559.tar.log"stimp_13295: Content-Type: application/octet-streamstimp_13295: stimp_13295: stimp_13295: HTTP/1.0 200 OKstimp_13295: Connection: keep-alivestimp_13295: Content-Type: text/plain; charset=utf-8stimp_13295: stimp_13295: stimp_13295: stimp_13295: DONE!stimp_13295: stimp_13295: EXITstimp_13297: stimp_13297: POST / HTTP/1.1stimp_13297: Host: 192.168.2.193:8080stimp_13297: Connection: keep-alivestimp_13297: Keep-Alive: 300stimp_13297: User-Agent: convertreguistimp_13297: Content-Type: multipart/form-data; boundary=---------------------7c9758f23dstimp_13297: Content-Length: 236203stimp_13297: Accept-Encoding: gzipstimp_13297: Accept-Language: ru-RU,en,*stimp_13297: -----------------------7c9758f23dstimp_13297: Content-Disposition: form-data; name="out_of_band"; filename="20120116141559.tar.log"stimp_13297: Content-Type: application/octet-streamstimp_13297: stimp_13297: stimp_13297: HTTP/1.0 200 OKstimp_13297: Connection: keep-alivestimp_13297: Content-Type: text/plain; charset=utf-8stimp_13297: stimp_13297: stimp_13297: stimp_13297: DONE!stimp_13297: stimp_13297: EXIT
[root@KS0000 ~]# logreceiver 4000 | grep stimpstimp_13291: stimp_13291: POST / HTTP/1.0stimp_13291: Host: 127.0.0.1stimp_13291: Referer: 127.0.0.1stimp_13291: Content-type: multipart/form-data; boundary=---------------------7c9758f23dstimp_13291: Content-length: 236203stimp_13291: -----------------------7c9758f23dstimp_13291: Content-Disposition: form-data; name="out_of_band"; filename="20120116141559.tar.log"stimp_13291: Content-Type: application/octet-streamstimp_13291: stimp_13291: stimp_13291: HTTP/1.0 200 OKstimp_13291: Connection: keep-alivestimp_13291: Content-Type: text/plain; charset=utf-8stimp_13291: stimp_13291: stimp_13291: stimp_13291: DONE!stimp_13291: stimp_13291: EXIT
HTTP/1.1 200 OKDate: Thu, 2 Feb 2012 17:14:02 MSKServer: Apache/2.2.16 (Debian)Last-Modified: Thu, 2 Feb 2012 17:14:02 MSKAccept-Ranges: bytesKeep-Alive: timeout=15, max=100Connection: Keep-AliveContent-Length: 6Content-Type: text/plain; charset=utf-8DONE!