Exemple #1
0
bool CFtpTransfer::upLoad(const QString sFilePath,const QString sFtpDir)
{
    qDebug()<<"upload";
    m_flagFtpOk=false;
    //先切出檔案名
    QUrl tmpUrl(sFilePath);
    QString sFileName=QFileInfo(tmpUrl.path()).fileName();
    qDebug()<<"sFIle  "<<sFilePath;
    //讀取檔源
    m_file.setFileName(sFilePath);

    if(!m_file.open(QIODevice::ReadWrite))
    {
        std::cerr<<"error : cannot write file ";
        return false;
    }
    //連線FTP
    m_ftp.connectToHost(m_url.host(),m_url.port(21));
    m_ftp.login(m_url.userName(),m_url.password());
    //上傳與指定檔名
    m_ftp.put(&m_file,sFtpDir+sFileName);
    cTimeOut(10000,m_flagFtpOk);
    m_file.close();
    m_ftp.close();
    return true;

}
Exemple #2
0
int main(int argc, char *argv[])
{
	std::priority_queue<MyUrl> downloadQueue;//设置待下载队列
	std::ifstream urlFile("url.txt");//打开种子url文件
	std::string urlStream,urlsStream;
	std::string tmpHtmlFile = "out.html";//临时存储下载html文件
	while(!urlFile.eof())
	{
		urlStream.clear();
		urlFile>>urlStream;
		urlsStream.append(urlStream);
		urlsStream.append("\r\n");
	}
	if(urlFile.is_open())
		urlFile.close();
	PaserUrl paser(tmpHtmlFile);
	//paser.getUrl(downloadQueue);
	/*DownloadUrl download;
	download.init();*/

	MyUrl tmpUrl("http://www.baidu.com",1);
	downloadQueue.push(tmpUrl);
	tmpUrl.setUrl("http://www.csdn.com");
	downloadQueue.push(tmpUrl);
	tmpUrl.setUrl("http://www.bing.com");
	downloadQueue.push(tmpUrl);
	curl_global_init(CURL_GLOBAL_WIN32);
	while(!downloadQueue.empty())
	{
		DownloadUrl download(downloadQueue.top(),tmpHtmlFile);
		paser = PaserUrl(tmpHtmlFile,downloadQueue.top());

		download.init();
		//download = downloadQueue.top();//获取优先级最高的url
		download.run();
		downloadQueue.pop();
		paser.parser(download.htmlData(),downloadQueue);//从返回的html文件中筛选出URL,并将其加入到待下载队列
		std::cout<<paser.getTitle()<<std::endl;
		std::cout<<paser.getContent()<<std::endl;
	}
	//QApplication a(argc, argv);
	//MainWindow w;
	//w.show();
	curl_global_cleanup();

	//return a.exec();
	system("pause");
}
DirItemInfo * DiskLocation::validateUrlPath(const QString& uPath)
{
    QString myPath(uPath);
    QFileInfo tmpUrl(uPath);
    if (tmpUrl.isRelative() && m_info)
    {
        tmpUrl.setFile(m_info->absoluteFilePath(), uPath);
        myPath  =  tmpUrl.absoluteFilePath();
    }
#if DEBUG_MESSAGES
    qDebug() << Q_FUNC_INFO << "path:" << myPath;
#endif
    DirItemInfo * item = new DirItemInfo(myPath);
    if (!item->isValid() || !item->exists() || !item->isContentReadable())
    {
        delete item;
        item = 0;
    }
    return item;
}
Exemple #4
0
bool CFtpTransfer::downLoad(const QString sFilePath,const QString sLocalDir)
{
    qDebug()<<"download";
    m_flagFtpOk=false;

    QUrl tmpUrl(sFilePath);
    QString sFileName=QFileInfo(tmpUrl.path()).fileName();

    if(!m_url.isValid())
    {
        std::cerr<<"Error: Invalid URL"<<std::endl;
        return false;
    }

    if(m_url.scheme() != "ftp")
    {
        std::cerr<<"Error: URL must start with 'ftp' ";
        return false;
    }



    QString tmp(sLocalDir);
    tmp.append(sFileName);
    m_file.setFileName(sLocalDir+sFileName);
    qDebug()<<"file Name:  "<<m_file.fileName();
    if(!m_file.open(QIODevice::ReadWrite))
    {
        std::cerr<<"error : cannot write file ";
        return false;
    }

    m_ftp.connectToHost(m_url.host(),m_url.port(21));
    m_ftp.login(m_url.userName(),m_url.password());
    m_ftp.get(tmpUrl.path(),&m_file);
    cTimeOut(10000,m_flagFtpOk);
    m_ftp.close();


    return true;
}