[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
about ssh_scp_write
[Thread Prev] | [Thread Next]
- Subject: about ssh_scp_write
- From: Dairon Dominguez Vega <ddvega@xxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Tue, 15 Mar 2011 11:20:57 -0500 (CST)
- To: libssh@xxxxxxxxxx
Hi, sorry for my bad english, but i have a problem. First, I'm open a connection with ssh_scp_new(...) and i set the flags (SSH_SCP_WRITE | SSH_SCP_RECURSIVE), next i invoke ssh_scp_push_file(..) and i put the size of the file that i have to copy and begin to sent to the host with ssh_scp_write(..) method. Now when my principal method is invoked recursively the method ssh_scp_push_file(...) return me an error(!= SSH_OK), my question is how can i sent a EOF to the host for it can know that i have finish the copy and can push a new file or something like this. Here is the method i'm using to copy an entire directory: ---I alredy I have inicialized scp whith no problems--- ssh_scp scp = ssh_scp_new(session, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, dirDest.toStdString().c_str()); ... void Connection::copyRecursive(ssh_scp scp, QString actualDir) { QFileInfo fileInfo(actualDir); const char* fileName = fileInfo.fileName().toStdString().c_str(); std::cout << fileName << std::endl; if(!fileInfo.isDir()) { int size = fileInfo.size(); int valOpt; std::cout << "SIZE " << size << std::endl; // valOpt = ssh_scp_push_file(scp, fileName, size, S_IRUSR | S_IWUSR); valOpt = ssh_scp_push_file(scp, fileName, size, 0644); if(valOpt != SSH_OK) { std::cout << " ERROR push_file " << std::endl; } /* * Writing data to file */ std::ifstream in; in.open(fileInfo.filePath().toStdString().c_str(), std::ios::in | std::ios::binary); if(!in.good()) { ConectionException<int> error(QString("Error abriendo el fichero \"%1\"."). arg(QString(fileInfo.filePath()))); error.setData(SCP_OPEN_FILE_ERROR); throw error; } int bytes = 0; int BUFFER_LENGTH = 16384; char buff[BUFFER_LENGTH]; // in.read(buff, 16834); do { in.read(buff, BUFFER_LENGTH); bytes += in.gcount(); valOpt = ssh_scp_write(scp, buff, in.gcount()); if(valOpt != SSH_OK) { std::cout << " ERROR ESCRIBIENDO " << std::endl; break; } }while (!in.eof()); in.close(); std::cout << " WRITED " << bytes << std::endl; /* *Escribiendo lo ultimo antes del EOF. */ // out.write(buff, in.gcount()); // ssh_scp_write(scp, buff, in.gcount()); // bytes += in.gcount(); //agregar envio de fin de fichero }else{ ssh_scp_push_directory(scp, fileName, S_IRWXU); QStringList files = QDir(actualDir).entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks, QDir::NoSort); int counter = 0; while(counter < files.size()) { std::cout << files.at(counter).toStdString() << std::endl; copyRecursive(scp, fileInfo.filePath() + QDir::separator() + files.at(counter)); ++counter; } ssh_scp_leave_directory(scp); } } thanks anyway. ***************** ** 养 虎 伤 身 ** ***************** -- ***************** ** 养 虎 伤 身 ** *****************
Archive administrator: postmaster@lists.cynapses.org