QFtp:upload file to server
I am confusing of uploading file to server.
I want know how I specified the path in the server.The file ,that will be uploaded,should be open,and copy to memory,then upload to the file which I created in the server...
May be I don't explain it clear,I just want to konw the process how the file upload to the server.
Thank you!!
Code:
int i = 0;
"D://");
if (files.isEmpty())
return;
while(files.indexOf("/", i) != (-1)) //find the file name not include the full url
i = files.indexOf("/",i) + 1;
while(i < files.size())
{
filename.append(files.at(i));
i++;
}
file = new QFile(filename
);
Q_ASSERT(file != NULL);
if(!file
->open
(QIODevice::ReadWrite)) //finished create the file in the debug file {
qDebug() << "opern err" << file->fileName();
return;
}
ftp->put(file,filename);
After the ftp->put , I find there is no file in the server directory.
Re: QFtp:upload file to server
I get the error information:"Uploading file failed:Cannot STOR. No permission.".So I find my ftp server have some problem, I create a anonymous client and have read/write permission, then upload file success.
But the file ,which will upload, should in my debug directory,how I can implement upload the file that in anywhere?The open function neet FILE * fh or int fd,not the file path, like
'D://Qt '.
Re: QFtp:upload file to server
Quote:
Originally Posted by
ensky_cy
I get the error information:"Uploading file failed:Cannot STOR. No permission.".So I find my ftp server have some problem, I create a anonymous client and have read/write permission, then upload file success.
But the file ,which will upload, should in my debug directory,how I can implement upload the file that in anywhere?The open function neet FILE * fh or int fd,not the file path, like
'D://Qt '.
Then why are you manually removing the full path. I have updated your code. Please try it.Kindly also check what debug messages comes.
Code:
int i = 0;
"D://");
if (files.isEmpty())
return;
file = new QFile(filename
);
Q_ASSERT(file != NULL);
{
qDebug() << "opern err" << file->fileName();
return;
}
qDebug() << "Upload strat";
ftp->put(file,filename);
qDebug() << "Upload end";
Re: QFtp:upload file to server
I have already solved this problem.I use the QDir to change the file directory.
Re: QFtp:upload file to server
Quote:
Originally Posted by
yogeshgokul
Then why are you manually removing the full path. I have updated your code. Please try it.Kindly also check what debug messages comes.
Code:
int i = 0;
"D://");
if (files.isEmpty())
return;
file = new QFile(filename
);
Q_ASSERT(file != NULL);
{
qDebug() << "opern err" << file->fileName();
return;
}
qDebug() << "Upload strat";
ftp->put(file,filename);
qDebug() << "Upload end";
Thank you!
The files is like:"D:/Qt/TCP/xxx.rar",and the filename is "xxx.rar".
We create the file(xxx.rar), not the file(D:/Qt/TCP/xxx.rar).So , I need to pick up the xxx.rar.
Re: QFtp:upload file to server
Quote:
Originally Posted by
ensky_cy
Thank you!
The files is like:"D:/Qt/TCP/xxx.rar",and the filename is "xxx.rar".
We create the file(xxx.rar), not the file(D:/Qt/TCP/xxx.rar).So , I need to pick up the xxx.rar.
For that you doesn't need to write so much as you have written.
Just 2 lines are enough
Re: QFtp:upload file to server
yes ,QFileInfo is useful.