PDA

View Full Version : Sending Binary File with QFTP



nbkhwjm
4th March 2007, 15:47
I know this is a Major Noob question, but all the examples i can find are of an FTP GET not an FTP PUT. I have several of the books on QT, nothing on Opening a file and PUTing it..


All i want to do is see some examples of opening a file and using QFTP PUTing it to a remote ftp as anonymous

The transfer must be binary safe.

I have this code to update a combo box with a filename from a browse button...


void Window::browse()
{
QString directory = QFileDialog::getOpenFileName(this,
tr("Open File"), QDir::currentPath());
if (!directory.isEmpty()) {
directoryComboBox->addItem(directory);
directoryComboBox->setCurrentIndex(directoryComboBox->currentIndex() + 1);
}
}

This works fine, then when they push Send it calls "sendFile", but I cannot link the "directoryComboBox" to the QFTP PUT... and send it to the server.

Send File Code...


void Window::sendFile()
{

cancelButton->setEnabled(true);

ftp = new QFtp(this);

/* This holds the remote server IP Address */
ftp->connectToHost(printerComboBox->currentText());

/* These Status labels are broken they work but show sending file allways, need to do better checking later */
statusLabel->setText(tr("Connecting to printer at %1 using FTP")
.arg(printerComboBox->currentText()));
ftp->login();

statusLabel->setText(tr("%1 - Logging in...")
.arg(printerComboBox->currentText()));

/* NEED TO REPLACE THIS WITH THE PROPER FILE OPEN AND SEND */
ftp->list();

statusLabel->setText(tr("%1 - Sending File...")
.arg(printerComboBox->currentText()));
}

I put in the "list();" command where the FTP PUT should be to make sure that the QFTP was doing something on the network, which it does. Now i need to actually open the file and send it.

Thanks all, this is my first ... Real (one that does something) QT network APP. Thanks for the assistance.

wysota
4th March 2007, 16:05
Try something like this:

QFile *file = new QFile("filepath", this);
file->open(QFile::ReadOnly);
ftp->put(file, "remotefilename");

nbkhwjm
7th March 2007, 18:10
works perfectly, I now have my first "real" C++ app... (something that isnt "hello world"!)