문제

I am trying to upload a file to a FTP server, which is a local server created by vsftpd. I have set necessary parameters needed for connecting and transferring files in the vsftpd.conf file. My requirement is to upload a file to this server. When i logged statechanged messages, HostLookup, Connecting, Connected, Logged in, closing, and Unconnected messages were emitted by my ftp object. But when i check in the destination directory the file is there but of 0 size...What could be wrong? following is the code I used...

QImage img("./Sample.jpg");
QBuffer* buf = new QBuffer();
buf->open(QBuffer::ReadWrite);
buf->seek(0);
img.save(buf, "jpg");
connection = new QFtp();
connection->connectToHost("localhost");
connection->login();
connection->cd("ftpshare/");
connection->put(buf, "Sample.jpg", QFtp::Binary);
qDebug(QString::number(connection->error()).toLatin1());
qDebug(connection->errorString().toLatin1());
connect(connection,SIGNAL(stateChanged(int)),this,SLOT(ftpstatechanged(int)));
connection->close();
도움이 되었습니까?

해결책 2

The problem was with usage of buffer. It got solved when I used QByteArray instead.

QImage img("./Sample.png");
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG");
connection = new QFtp();
connection->connectToHost("localhost");
connection->login();
connection->cd("ftpshare/");
connection->put(ba, "Sample.png", QFtp::Binary);

다른 팁

Are you sure the first line of finds the Sample.jpg in the folder it is looking in? Maybe the working directory is not what you think it is. Otherwise this should work just fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top