Repository navigation
Expand file tree
/
Copy pathup.cpp
More file actions
67 lines (52 loc) · 1.44 KB
/
Copy pathup.cpp
File metadata and controls
67 lines (52 loc) · 1.44 KB
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
#include "up.h"
#include "ui_up.h"
up::up(QWidget *parent) :
QWidget(parent),
ui(new Ui::up)
{
ui->setupUi(this);
}
up::~up()
{
delete ui;
}
void up::start(const QString &file){
// no passwd
// QUrl url("ftp://172.20.5.167/ftp.txt");
QUrl url;
url.setScheme("ftp");
//url.setHost("10.106.20.250");
url.setHost("10.108.13.158");
QFileInfo info(file);
QString name=info.fileName();
// 这里是设置远端主机上传时的文件名,不设置则名称为本地端上传名称
url.setPath(name);
// url.setUserName("root");
url.setPort(21);
// need passwd
/*
QUrl url("ftp://172.20.5.167/ftp.txt");
url.setScheme("ftp");
url.setUserName("root");
url.setPort(21);
*/
data = new QFile(file, this);
if (data->open(QIODevice::ReadOnly)) {
qDebug()<<"open";
reply = nam.put(QNetworkRequest(url), data);
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(uploadProgress(qint64, qint64)));
connect(reply, SIGNAL(finished()), SLOT(uploadDone()));
}
else
qDebug() << "Oops";
}
void up::uploadProgress(qint64 bytesSent, qint64 bytesTotal) {
ui->progressBar->setMaximum(bytesTotal);
ui->progressBar->setValue(bytesSent);
qDebug() << "Uploaded" << bytesSent << "of" << bytesTotal;
}
void up::uploadDone(){
qDebug() << "Finished" << reply->error();
data->deleteLater();
reply->deleteLater();
}